﻿// JScript File

function OpenWindow(url,width,height,scroll)
{
  try{
      window.open(url,'pop','letf=0,top=0,width='+ width +',height='+ height +',toolbar=0,scrollbars='+scroll+',status=0');
    return false;
    }
    catch (ex)
    {}
    
}
 
 Isnumeric = function(e)
 { 
    var keynum;
    var keychar;
    var numcheck;

    if(window.event) //  IE
    {
        keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    if(keynum == null || keynum == 8)
        return true

    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;
    return numcheck.test(keychar);
}

function isNumberKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}

function resizeIframeToFitContent(iframe_id)
{
//    //find the height of the internal page
//      var the_height= window.frames[iframe_id].document.body.scrollHeight;
//    //change the height of the iframe
//      document.getElementById(iframe_id).height= the_height+30;
//      var the_height=document.getElementById(iframe_id).contentWindow.document.body.scrollHeight;
//      document.getElementById(iframe_id).height=the_height;
//alert(contentWindow.document.body.scrollHeight);
   if (iframe_id.contentDocument != null) // firefox 
    { 
        iframe_id.height = iframe_id.contentDocument.height; 
        alert(iframe_id.height);
    } 
    else // IE 
    { 
        iframe_id.style.height = iframe_id.contentWindow.document.body.scrollHeight; 
        alert(iframe_id.style.height);
 
    } 
    
}

//this script is used for star active and inactive
  function ChangeActiveStar(id,no,hidVal)
    { 
        if(no==1)
        {
            if(id.alt=="show")
            {
                if(document.getElementById("img"+(no+1)).alt=="hide")
                {
                    id.src="Images/star-empty.png";
                    id.alt="hide";
                     hidVal.value = parseInt(hidVal.value) - 1;
                }
            }
            else
            {
                id.src="Images/star-filled.png";
                id.alt="show";
                hidVal.value = 1;
            }
        }
        else
        {
             if(document.getElementById("img"+(no-1)).alt=="show")
             {
                    if(id.alt=="show")
                    {
                        if(no==5)
                            {
                                 id.src="Images/star-empty.png";
                                 id.alt="hide";
                             }
                             else
                             {
                                   if(document.getElementById("img"+(no+1)).alt=="hide")
                                    {
                                        id.src="Images/star-empty.png";
                                        id.alt="hide";
                                    }
                             }
                            hidVal.value = parseInt(hidVal.value) - 1;
                     }
                     else
                      {
                         id.src="Images/star-filled.png";
                         id.alt="show";
                         hidVal.value = parseInt(hidVal.value) + 1 ;
                      }
               }
          }
    }
    
    function StarClick(id,no,hidVal)
        {
            for (var x = 1; x <= no; x++)
              {
                document.getElementById("img"+(x)).src="Images/star-filled.png"; 
                document.getElementById("img"+(x)).alt="show";
                
              }
              if(no != 5)
              {
                for (var y = no+1; y <= 5; y++)
                  {
                    document.getElementById("img"+(y)).src="Images/star-empty.png"; 
                    document.getElementById("img"+(y)).alt="hide";
                  }
              }
              hidVal.value = no;
        }
    
    function SetValue(val,hidVal)
    {
     for (var x = 1; x <= val; x++)
      {
       var id=document.getElementById("img"+x);
          id.src="Images/star-filled.png";
         id.alt="show";
      }
    }

function ChkNumericNTrapEnter_onkeypress(e, btn) 
		{
		    var button=document.getElementById(btn);
			var key //= (window.event) ? event.keyCode : e.which;

			if (window.event)  
				key = event.keyCode 
			else  
				key = e.which  
			 	
				// Was key that was pressed a numeric character (0-9) or backspace (8)? 
				//if ( key > 47 && key < 58 || key == 8 )  
				//return; // if so, do nothing   

				if ( key == 13)
				{
					if (window.event) //IE 
					{   
						window.event.returnValue = null; 
						window.event.cancel = true;
					}  
					else
					{
						e.cancel = true;
						e.returnValue = false;
					}
					button.click();
					return false;
				}
			}
			
			
			
function BasketTotal(Qty,Total)
{ 
 try{
  document.getElementById("ctl00_lblBasketItem").innerHTML=Qty;
  document.getElementById("ctl00_lblBasketPrice").innerHTML=Total.toFixed(2);
  }
  catch(ex){}

}


function textLimit(field) 
{ 
   var maxlimit=10;
   var txtid=field;
   //var lblid=document.getElementById(countfield);
   if (txtid.length > maxlimit) // if too long...trim it!
   {			
      return txtid.substring(0, maxlimit);
   }
  else 
  {
      return (maxlimit - (txtid.length));
  }
} 



function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  
  // Overseas Territories
  pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}

function UkPostCode(id) {

  var myPostCode = document.getElementById(id).value;
  if (checkPostCode (myPostCode)) {
    document.getElementById(id).value = checkPostCode(myPostCode)
    return true;
  } 
  else {alert ("Postcode has invalid format");return false;};
  
  }

	




    

 
   
