function cs(e, eventTarget, eventArgument)
{
	if (e.keyCode == 13 || e.which == 13)
	{		
		return doPB(e, eventTarget, eventArgument)
	}
	return false;
}

function doPB(e, eventTarget, eventArgument)
{
		if (e.preventDefault) e.preventDefault();
		if (e.stopPropagation) e.stopPropagation();
		//if (e.preventBubble) e.preventBubble();
		e.cancelBubble = true;
		e.returnValue = false;
		if (typeof(__doPostBack) == 'function'){
			__doPostBack(eventTarget, eventArgument);
		}
		else {
		var theform = document.forms[0];
		theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
		theform.__EVENTARGUMENT.value = eventArgument;
		theform.submit();
		}
		return false;
}

function swImage(url) {
	NewWindow(url,'',500,500,1,1,100,100);	
}

function swPopup(url) {
	NewWindow(url,'',440,300,1,1,100,100);
}

function NewWindow(url, title, w, h, winResize, winScroll, winLeftPos, winTopPos) {
	if(title == null) title = '';
	if(w == null) w = '600';
	if(h == null) h = '500';
	if(winResize == null) bResize = 'yes';
	if(winScroll == null) bScroll = 'yes';
	if(winLeftPos == null) winLeftPos = (screen.width-w)/2;
	if(winTopPos  == null) winTopPos  = (screen.height-h)/2;	
	settings = 'width='+w+',height='+h+',top='+winTopPos+',left='+winLeftPos+',scrollbars='+winScroll+',resizable='+winResize+',location=no,directories=no,status=no,menubar=no,toolbar=no';
	win = window.open(url, title, settings)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function cvIsNumeric(source, arguments) {
		arguments.IsValid = (parseInt(arguments.Value) > 0)?true:false;
}
 
function swDisplay(elemId,imgId,bShowElem) { 
	var o = document.getElementById(elemId);	
 	if(o == null || o == null) return false; 	
 	if(bShowElem != null) { 	
  		o.style.display=(bShowElem)?"block":"none";
 	}
 	else { 	
 		o.style.display=(o.style.display=="none")?"block":"none";
 	} 	
 	if(imgId != null) { 	 	
 		var oimg = document.getElementById(imgId);
 		if(oimg != null || oimg != null){
 			var s=(o.style.display=="none")?"add.gif":"sub.gif";
  			setTimeout("document.getElementById('"+imgId+"').src='../images/"+s+"'", 10);  			
  		}
 	}
} 

function showCCDetails(obj) {
    if(obj == null) return false;
    var cctype = obj.options[obj.selectedIndex].value;

    var _UK_Start = document.getElementById("_UK_Start");
    var _UK_Issue = document.getElementById("_UK_Issue");
    if(_UK_Start != null && _UK_Issue != null)
    {
	  _UK_Start.style.display = "none";
 	  _UK_Start.style.height = "0";

	  _UK_Issue.style.display = "none";
      _UK_Issue.style.height = "0";  		
      if (cctype == 'VISD') {
	    _UK_Start.style.display = "";
	    _UK_Start.style.height = "auto";
      }
      else if (cctype == 'SOLO' || cctype == 'MAE')
      {
	    _UK_Start.style.display = "";
	    _UK_Issue.style.display = "";
	    _UK_Issue.style.height = "auto";
	    _UK_Start.style.height = "auto";
      }
    }
}

/* valdate credit card number */
function cvIsCardNum(source, arguments) {

	var s = arguments.Value
	var v = "0123456789";
	var w = "";

	for (var i=0; i < s.length; i++) {
		x = s.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
		
	var j = w.length / 2;	
	if (j < 6.5 || j > 8 || j == 7) {
		arguments.IsValid = false;
		return arguments.IsValid;
	}

	var k = Math.floor(j);
	var m = Math.ceil(j) - k;
	var c = 0;
	
	for (var i=0; i<k; i++) {
		a = w.charAt(i*2+m) * 2;
		c += a > 9 ? Math.floor(a/10 + a%10) : a;
	}
	
	for (var i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
	
	arguments.IsValid = (c%10 == 0);
	return arguments.IsValid;
}

//add option to ddl
function addOption(ddl,text,value) {
	var op = document.createElement("OPTION");
	op.text = text;
	op.value = value;
	ddl.options.add(op);
}

function checkValidState(source, arguments) {
     var checkControlId = source.id.replace("Validator_","");
     var dropDownListToValidate = document.getElementById(checkControlId);
    
     if(dropDownListToValidate.style.display != "none") {
        arguments.IsValid = (dropDownListToValidate.selectedIndex > 0);
     }else {
        arguments.IsValid = true;
     }
     //alert(arguments.IsValid);
}

//UserAccount.ascx, ViewCart.ascx
function setStateLayout(cid,selValue) {
	if(selValue == null) selValue = '';
	uid = uid.split(":").join("_");
	uid = uid.split("$").join("_"); //.NET 2.0
	var c, c1, c1d, c2;
	if(cid=='b' || cid=='s'){
		c = document.getElementById(uid+'_'+cid+'country');
		c1 = document.getElementById(uid+'_'+cid+'state');		
		c2 = document.getElementById(uid+'_'+cid+'state_textbox');	
		c1d = c1;
	}
	else {
		c = document.getElementById(uid+'_ddlCountry');
		c1 = document.getElementById(uid+'_ddlState');
		c1d = document.getElementById(uid+'_stateRow');
	}	
	if(c == null || c1 == null) return;
	if(typeof(arrCCL) == "undefined") { //no countries with states
		c1d.style.display="none";
		c1.options.selectedIndex=0;						
		if(c2 != null){c2.style.display="block";}
		return;
	}
	var ccode = c.options[c.selectedIndex].value;
	var i;
	for(i=0; i<arrCCL.length; i++)
	{
		if(ccode == arrCCL[i])
		{			
			var arr;
			try { arr = eval('arr'+ccode) } catch (e) {};
			if(arr == null) return;
			for(i=c1.length-1; i>=0; i--){c1.options[i] = null;}
			for(i=0; i<=arr.length-2; i+=2){
				addOption(c1,arr[i+1],arr[i]);				
			}
			for(i=0; i<c1.length; i++){
			  if(c1.options[i].value == selValue){
			    c1.selectedIndex = i;
			    break;			    
			  }
			}
			c1d.style.display="";
			if(c2 != null){c2.style.display="none";}
			return;
		}
		else {
			c1d.style.display="none";
			c1.options.selectedIndex=0;						
			if(c2 != null){c2.style.display="block";}
		}	
	}
}

function PostcodeAnywhere_Interactive_FindByPostcode_v1_00Begin(Key, Postcode, UserName)
{
      var scriptTag = document.getElementById("PCA8606e2f1a83c4c08b6a2680c220da98c");
      var headTag = document.getElementsByTagName("head").item(0);
      var strUrl = "";

      //Build the url
      strUrl = "http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/FindByPostcode/v1.00/json.ws?";
      strUrl += "&Key=" + encodeURI(Key);
      strUrl += "&Postcode=" + encodeURI(Postcode);
      strUrl += "&UserName=" + encodeURI(UserName);
      strUrl += "&CallbackFunction=PostcodeAnywhere_Interactive_FindByPostcode_v1_00End";

      //Make the request
      if (scriptTag) 
         {
            try
              {
                  headTag.removeChild(scriptTag);
              }
            catch (e)
              {
                  //Ignore
              }
         }
      scriptTag = document.createElement("script");
      scriptTag.src = strUrl
      scriptTag.type = "text/javascript";
      scriptTag.id = "PCA8606e2f1a83c4c08b6a2680c220da98c";
      headTag.appendChild(scriptTag);
   }



