String.prototype.Trim = function(){ return this.replace(/^\s+|\s+$/g,'') }

var xmlHttp
var xmlHttp2

function isFloat(iNumber){
  var isOK = true;
  var iMinus = 0;
  var iComma = 0;
  if ((iNumber == null) ||(iNumber == "")){
    isOK = false;
    return isOK; 
  }
  for (j=0; j<iNumber.length; j++) {
    if ((iNumber.substring(j,j+1) != "0") &&
        (iNumber.substring(j,j+1) != "1") &&
        (iNumber.substring(j,j+1) != "2") &&
        (iNumber.substring(j,j+1) != "3") &&
        (iNumber.substring(j,j+1) != "4") &&
        (iNumber.substring(j,j+1) != "5") && 
        (iNumber.substring(j,j+1) != "6") &&
        (iNumber.substring(j,j+1) != "7") &&
        (iNumber.substring(j,j+1) != "8") &&
        (iNumber.substring(j,j+1) != "9") &&
        (iNumber.substring(j,j+1) != ".") &&
        (iNumber.substring(j,j+1) != "-")) {
       isOK = false
     }
     if (iNumber.substring(j,j+1) == "-" ) iMinus += 1;
     if (iNumber.substring(j,j+1) == "." ) iComma += 1;
  }
  if (iMinus>1) isOK = false;
  if (iComma>1) isOK = false;
  return isOK;
}

function isEmail(sValue){
  var isOK = true;
  var iLength = sValue.length;
  var iArr = 0;
  var iDot = 0;
  if (iLength < 6){
     isOK = false;
     return isOK;
  }
  for (j=0; j<iLength; j++){
    if((sValue.substring(j,j+1) == "'") ||
       (sValue.substring(j,j+1) == "*") ||
       (sValue.substring(j,j+1) == "%") ||
       (sValue.substring(j,j+1) == ",") ||
       (sValue.substring(j,j+1) == "&") ||
       (sValue.substring(j,j+1) == "/") ||
       (sValue.substring(j,j+1) == "$") ||
       (sValue.substring(j,j+1) == "=") ||
       (sValue.substring(j,j+1) == "#") ||
       (sValue.substring(j,j+1) == "?") ||
       (sValue.substring(j,j+1) == "¿") ||
       (sValue.substring(j,j+1) == "<") ||
       (sValue.substring(j,j+1) == ">") ||
       (sValue.substring(j,j+1) == "\"")) {
      isOK = false;
     }
     if (sValue.substring(j,j+1) == "@") iArr += 1;
     if (sValue.substring(j,j+1) == ".") iDot += 1;
  }
  if (iArr != 1) isOK = false;
  if (iDot < 1) isOK = false;
  return isOK;
}

function isInteger(iNumber, iSW){
  var isOK = true;
  var iMinus = 0;
  if ((iNumber == null) ||(iNumber == "")){
    isOK = false;
    return isOK; 
  }
  for (j=0; j<iNumber.length; j++) {
    if ((iNumber.substring(j,j+1) != "0") &&
        (iNumber.substring(j,j+1) != "1") &&
        (iNumber.substring(j,j+1) != "2") &&
        (iNumber.substring(j,j+1) != "3") &&
        (iNumber.substring(j,j+1) != "4") &&
        (iNumber.substring(j,j+1) != "5") && 
        (iNumber.substring(j,j+1) != "6") &&
        (iNumber.substring(j,j+1) != "7") &&
        (iNumber.substring(j,j+1) != "8") &&
        (iNumber.substring(j,j+1) != "9") &&
        (iNumber.substring(j,j+1) != "-")) {
       isOK = false
     }
     if (iNumber.substring(j,j+1) == "-" ) iMinus += 1;
  }
  if (iNumber.substring(0,1) == "0") isOK = false
  if (iMinus>1) { 
      isOK = false;   
  }else{
    if (iMinus == 1) {
       if (iNumber.substring(0,1) != "-") { 
            isOK = false;
       }else{
         if (!iSW) isOK = false;
       }
    }
  } 
  return isOK;
}

function EraseDefaultText(iText){
  var xText = document.frmSearch.SearchKey.value;
  if (xText == iText) {
    document.frmSearch.SearchKey.value = "";
  }
}

function SetDefaultText(iText){
  var xText = document.frmSearch.SearchKey.value;
  if (xText == "") {
    document.frmSearch.SearchKey.value = iText;
  }
}

function DoSearch(iText){
  var xText = document.frmSearch.SearchKey.value;
  if ((xText != "") && (xText != iText)) {
    document.frmSearch.submit();
  }
}

function Sel(iObj){
  iObj.className = "ProductSnipletSel";
}

function Unsel(iObj){
  iObj.className = "ProductSniplet";
}

function ShareProduct(iCode){
  window.open("/ShareProduct.asp?pid=" + iCode,"wndShare","width=600, height=580, status=no, toolbar=no ,menubar=no,resize=no");
}

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

function AddWishListChanged()
{
  if (xmlHttp.readyState==4)
  {          
    document.getElementById("LayerAreaWishListButton").innerHTML = xmlHttp.responseText;
    UpdateWishList();
  }
}

function AddWishList(iProdID)
{    xmlHttp=GetXmlHttpObject();
     if (xmlHttp == null)
     {  
     }
     else
     { 
        var url = "/ADSC/AJAX/AjaxWishListManager.asp?tg=ADD&pid=" + iProdID;
        xmlHttp.onreadystatechange=AddWishListChanged;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
      }
}

function AddCompareChanged()
{
  if (xmlHttp.readyState==4)
  {          
    document.getElementById("LayerAreaCompareButton").innerHTML = xmlHttp.responseText;
    UpdateCompare();
  }
}

function AddCompare(iProdID)
{    xmlHttp=GetXmlHttpObject();
     if (xmlHttp == null)
     {  
     }
     else
     { 
        var url = "/ADSC/AJAX/AjaxCompareManager.asp?tg=ADD&pid=" + iProdID;
        xmlHttp.onreadystatechange=AddCompareChanged;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
      }
}


function AddCompareChangedText()
{
  if (xmlHttp.readyState==4)
  {          
    document.getElementById("LayerAreaCompareText").innerHTML = xmlHttp.responseText;
    //UpdateCompare();
  }
}

function AddCompareText(iProdID){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp == null){
	}else{
		var url = "/ADSC/AJAX/AjaxCompareManager.asp?tg=ADDtext&pid=" + iProdID;
		xmlHttp.onreadystatechange=AddCompareChangedText;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}



function UpdateWishListChanged()
{
  if (xmlHttp.readyState==4)
  {          
    document.getElementById("LayerFrameRightPanelWishList").innerHTML = xmlHttp.responseText;
    //UpdateBulk();
  }
}

function UpdateWishList()
{    xmlHttp=GetXmlHttpObject();
     if (xmlHttp == null)
     {  
     }
     else
     { 
        var url = "/ADSC/AJAX/AjaxWishListManager.asp?tg=UPDATE";
        xmlHttp.onreadystatechange=UpdateWishListChanged;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
      }     
}

function UpdateCompareChanged()
{
  if (xmlHttp.readyState==4)
  {          
    document.getElementById("LayerFrameRightPanelCompare").innerHTML = xmlHttp.responseText;
    //UpdateBulk();
  }
}

function UpdateCompare()
{    xmlHttp=GetXmlHttpObject();
     if (xmlHttp == null)
     {  
     }
     else
     { 
        var url = "/ADSC/AJAX/AjaxCompareManager.asp?tg=UPDATE";
        xmlHttp.onreadystatechange=UpdateCompareChanged;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
      }     
}








function RemoveWishList(iCode){
  if (confirm("Are you sure to remove item from WishList?")){
    window.location.href="/ADSC/ajax/AjaxWishListManager.asp?tg=REMOVE&index=" + iCode;
  }
}

function ShareProductSend(){
  var xMsg = "";
  if (document.frmShare.txtName.value.Trim()=="") xMsg += "\nYour Name";
  if (!isEmail(document.frmShare.txtEmail.value.Trim())) xMsg += "\nYour Email Address";
  if (document.frmShare.txtFName.value.Trim()=="") xMsg += "\nYour Friend's Name";
  if (!isEmail(document.frmShare.txtFEmail.value.Trim())) xMsg += "\nYour Friend's Email Address";
  if (xMsg == ""){
  	document.getElementById('tr_buttons').style.display = 'none';
  	document.getElementById('tr_mssg').style.display = '';
    document.frmShare.submit();
  }else{
    alert("Please fill the following fields before to continue:\n" + xMsg);
  }
}

function GoRemoveItem(pid){
	window.location.href = 'CompareItems.asp?tg=REMOVE_ITEM&pid=' + pid;
}


function RemoveItemCompare(index)
{    xmlHttp=GetXmlHttpObject();
     if (xmlHttp == null)
     {  
     }
     else
     { 
        var url = "/ADSC/AJAX/AjaxCompareManager.asp?tg=REMOVE&index=" + index;
        xmlHttp.onreadystatechange=RemoveItemCompareChanged;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
      }
}

function RemoveItemCompareChanged()
{
  if (xmlHttp.readyState==4)
  {          
    document.getElementById("LayerAreaCompareButton").innerHTML = xmlHttp.responseText;
    UpdateCompare();
  }
}

function ShareProductAgain(kPID, kName, kEm0, kEm1){
	window.location.href = "ShareProduct.asp?pid=" +kPID+ "&Name=" +kName+ "&Em0=" +kEm0+ "&Em1=" +kEm1;
}

function SelPG(iObj){
  iObj.className = "ProductTableBorderOrange";
}

function UnselPG(iObj){
  iObj.className = "ProductTableBorderGray";
}

function SaveCompareAll(){
	document.frmProductsGrid.submit();
}



function bookmarksite(title,url){
	if (window.sidebar && window.sidebar.addPanel) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print) // opera
		{
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		}
		else if(document.all)// ie
			window.external.AddFavorite(url, title);
}


function bookmarksiteGG(title,url){
	if (navigator.appName != 'Microsoft Internet Explorer')
		window.sidebar.addPanel(title, url, '');
	else if(window.opera && window.print)
		{
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		}
		else if(document.all)
	        window.external.AddFavorite(url, title);
}

function keyDownEnter(e){
	var name = "";
	if (document.all) {
		if (e.keyCode == 13) document.frmSearch.submit();
	}else
		if (e.which == 13) document.frmSearch.submit()
}




