﻿var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};



function change_style(myobj, mybgcolor){
//alert(myobj);

    myobj.style.background = "#" + mybgcolor;
  
}


function IsNumber(strField)
//  check if string value is numeric
{
   var strValidChar = ".)-(,+1234567890";
   var strChar;
   var BooleanResult = true;
   
  if (strField.length == 0) return false;
   // test the string for valid characters
   for (i = 0; i < strField.length && BooleanResult == true; i++)
      {
          strChar = strField.charAt(i);
          if (strValidChar.indexOf(strChar) == -1)
             {
                BooleanResult = false;
             }
      }
   return BooleanResult;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function IsEmail(Expression)
//check if email address valid
{
	if (Expression == null)
		return (false);

	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (Expression.indexOf(".") > 2) && (Expression.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,5}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(Expression) && r2.test(Expression));
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//Navigate somewhere using button
function buttonNavigate(newLocation)
{
    window.location = newLocation;
}

/*
    function to change the page order of category listing and search result pages
*/
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function ChangePageOrder(myObj){

        var Value = myObj[myObj.selectedIndex].value;
        var BaseURL = document.location + '';
        
        var is_search = false;
        if(BaseURL.toLowerCase().indexOf("/search/") > -1){
            is_search = true;
        }
        
        var MatchString = 'order__';
        MatchString = MatchString.toLowerCase();
        
        var StartPos = BaseURL.toLowerCase().indexOf(MatchString);
        
        if(StartPos > -1){
            var BasePart1;
            var BasePart2 = '';
            var EndPos = BaseURL.indexOf('/', StartPos);
            
            BasePart1 = BaseURL.substr(0, StartPos);
            
            if(EndPos > -1){
                BasePart2 = BaseURL.substr(EndPos+1, BaseURL.length)
            }
            
            if(BasePart2 == '/'){
                BasePart2 = '';
            }
            BaseURL = BasePart1 + BasePart2;
        }
        if(BaseURL.length-1 != BaseURL.lastIndexOf('/')){
            BaseURL = BaseURL + '/';
        }
        
        if(is_search){
            if(Value != 'r'){
                BaseURL = BaseURL + 'order__' + Value + '/';
            }
        }else{
            if(Value != 'pr'){
                BaseURL = BaseURL + 'order__' + Value + '/';
            }
        }
        
        myObj.disabled = true;

        BaseURL = Remove_Paging(BaseURL);
        document.location = BaseURL;
        
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function createXMLHttp(){
	var myobj;
	try {myobj = new ActiveXObject("Msxml2.XMLHTTP.4.0");}
	catch (ex){ try {myobj = new ActiveXObject("Msxml2.XMLHTTP.3.0");}
	catch (ex){ try {myobj = new ActiveXObject("Msxml2.XMLHTTP");}
	catch (ex){ try {myobj = new ActiveXObject("Microsoft.XMLHTTP");}
	catch (ex){ try {myobj = new XMLHttpRequest();}
	catch (ex){ myobj = false; alert("Could not load XMLHTTP component");}}}}}
	return myobj;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function AjaxCall(path,data,msgElement,message)
{
   var xmlhttp = createXMLHttp();
   xmlhttp.open("POST",path,false);
   xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   xmlhttp.send(data);

   //alert(xmlhttp.responseText)+"*****";

   //returns text to screen
   if (msgElement != "")
   {
        document.getElementById(msgElement).value = message;   
   }
   
   return(xmlhttp.responseText);   
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------

/*
    function to change the price filter of category listing and search result pages
*/
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function ChangePriceFilter(allowed_min, allowed_max){
    var min_price = document.frmPriceFilter.price_min.value;
    var max_price = document.frmPriceFilter.price_max.value;
    
    var Error = 0;
    
    if(!IsNumber(min_price)){
        Error = 2
    }else if(!IsNumber(max_price)){
        Error = 3
    }else{
        
        if(min_price*1 >= max_price*1){
            Error = 4
        }
        
        if(min_price < allowed_min){
            if(max_price < allowed_min){
                Error = 1;
            }
        }
        if(min_price > allowed_max){
            Error = 1;
        }
        
        
    }
    
    if(Error == 1){ 
       min_price =  allowed_min;
       max_price =  allowed_max;
    }
    
    if(Error >= 2){  

        ErrMsg = "There was a problem with your Price Range filter\n\n";
        ErrMsg = ErrMsg + "Please make sure that you only enter numeric values\n";
        ErrMsg = ErrMsg + "and that the minimum value is less than the maximum value\n";
    
        alert(ErrMsg);
        
    }else{


        var BaseURL = document.location + '';
        
        var MatchString = 'pricerange__';
        MatchString = MatchString.toLowerCase();
        
        var StartPos = BaseURL.toLowerCase().indexOf(MatchString);
        
        if(StartPos > -1){
            var BasePart1;
            var BasePart2 = '';
            var EndPos = BaseURL.indexOf('/', StartPos);
            
            BasePart1 = BaseURL.substr(0, StartPos);
            
            if(EndPos > -1){
                BasePart2 = BaseURL.substr(EndPos+1, BaseURL.length)
            }
            
            if(BasePart2 == '/'){
                BasePart2 = '';
            }
            BaseURL = BasePart1 + BasePart2;
        }
        if(BaseURL.length-1 != BaseURL.lastIndexOf('/')){
            BaseURL = BaseURL + '/';
        }
        
        if(min_price < 0){
            min_price = 0;
        }
        
        BaseURL = BaseURL + 'pricerange__' + Math.round(min_price) + '_'+ Math.round(max_price) +'/';
        
        BaseURL = Remove_Paging(BaseURL);
        
        document.location = BaseURL;

    
    }

    return false;
}




/*
    function to search within results
*/
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function Change_search_in_results(){

    var new_search = document.frm_search_in_results.new_search.value;
    
    var Error = 0;
    
    var BaseURL = document.location + '';
    
    var MatchString = 'kw__';
    MatchString = MatchString.toLowerCase();
    
    var StartPos = BaseURL.toLowerCase().indexOf(MatchString);

    var BasePart3 = '';
    
    if(StartPos > -1){
        var BasePart1;
        var BasePart2 = '';
        
        var EndPos = BaseURL.indexOf('/', StartPos);
        
        if(EndPos == -1){
            EndPos = BaseURL.length;
        }
        
        BasePart1 = BaseURL.substr(0, StartPos);
        
        
        if(EndPos > -1){
            BasePart2 = BaseURL.substr(EndPos+1, BaseURL.length);
        }
        
        if(BasePart2 == '/'){
            BasePart2 = '';
        }
        
        BasePart3 = BaseURL.substr(StartPos, EndPos-StartPos);
        
        BaseURL = BasePart1 + BasePart2;
    }
    
    if(BaseURL.length-1 != BaseURL.lastIndexOf('/')){
        BaseURL = BaseURL + '/';
    }
    
    new_search = new_search.replace(' ', '+');
    
    if(BasePart3.length > 0){
        BaseURL = BaseURL + BasePart3 + '__' + new_search;
    }else{
        BaseURL = BaseURL + 'kw__' + new_search;
    }
    
    
    alert(BaseURL);
    BaseURL = Remove_Paging(BaseURL);
    
    document.location = BaseURL;

    return false;
}

/*
    function to remove paging from URL
*/
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function Remove_Paging(Expression){

    var MatchString = 'page__';
    MatchString = MatchString.toLowerCase();
    
    var StartPos = Expression.toLowerCase().indexOf(MatchString);

    if(StartPos > -1){
        var BasePart1;
        var BasePart2 = '';
        
        var EndPos = Expression.indexOf('/', StartPos);
        
        if(EndPos == -1){
            EndPos = Expression.length;
        }
        
        BasePart1 = Expression.substr(0, StartPos);
        
        
        if(EndPos > -1){
            BasePart2 = Expression.substr(EndPos+1, Expression.length);
        }
        
        if(BasePart2 == '/'){
            BasePart2 = '';
        }
        
        Expression = BasePart1 + BasePart2;
    }


    return(Expression);
}

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function checkCC(s) {
  var i, n, c, r, t;
  r = "";
  for (i = 0; i < s.length; i++) {
    c = parseInt(s.charAt(i), 10);
    if (c >= 0 && c <= 9)
      r = c + r;
  }
  if (r.length <= 1)
    return false;
  t = "";
  for (i = 0; i < r.length; i++) {
    c = parseInt(r.charAt(i), 10);
    if (i % 2 != 0)
      c *= 2;
    t = t + c;
  }
  n = 0;
  for (i = 0; i < t.length; i++) {
    c = parseInt(t.charAt(i), 10);
    n = n + c;
  }
  if (n != 0 && n % 10 == 0)
    return true;
  else
    return false;
}

/* Image Paging for Product Details Page */
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function next_image(){
	img = document.getElementById("MainImage");
	
	viewing_image++;
	if(viewing_image >= images.length){
		viewing_image = 0;
	}

	img.src = images[viewing_image].src;
	
	document.getElementById("enlargeURL").value = images[viewing_image].src;
	
	document.getElementById("gallery_counter").innerHTML = viewing_image+1;
	
}

function prev_image(){
	img = document.getElementById("MainImage");
	
	viewing_image = viewing_image - 1;
	if(viewing_image < 0){
		viewing_image = images.length-1;
	}

	img.src = images[viewing_image].src;
	
	document.getElementById("enlargeURL").value = images[viewing_image].src;
	
	document.getElementById("gallery_counter").innerHTML = viewing_image+1;
	

}

/* Raplace InnerHTML of one Div with the InnerHTML of another */
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
function divReplace(SourceObjId, TargetObjId){

	var Obj1 = document.getElementById(TargetObjId)
	var Obj2 = document.getElementById(SourceObjId)

	if(Obj1 && Obj2){
		Obj1.innerHTML = Obj2.innerHTML;
		Obj2.innerHTML = "";
	}else{
	    //alert("error");
	}

}



/*****************************************************************************************/
/* Click Functions DO NOT TOUCH */
/*****************************************************************************************/
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------

function jmp_go(_obj1, _c1, _a, _c2, _s, _i, _d, _c, _pma, _pmi, _t){


    BrowserDetect.init();

    var U = '/click/?ts=1';
    U += '&_c1=' + escape(_c1);
    U += '&_a=' + escape(_a);
    U += '&_c2=' + escape(_c2);
    U += '&_s=' + escape(_s);
    U += '&_i=' + escape(_i);
    U += '&_d=' + escape(_d);
    U += '&_c=' + escape(_c);
    U += '&_t=' + escape(_t);
    U += '&_pma=' + escape(_pma);
    U += '&_pmi=' + escape(_pmi);
    U += '&_res=' + escape(screen.width+'x'+screen.height);
    U += '&_br=' + escape(BrowserDetect.browser + ' ' + BrowserDetect.version);
    U += '&_os=' + escape(BrowserDetect.OS);
    
    if(top.window.location){
        U += '&_loc=' + escape(top.window.location);
    }else{
        U += '&_loc=' + escape(document.location);
    }
    
    if(_obj1.action){
        if(_obj1.action.indexOf("#jmp_to_store") > -1){
            _obj1.action=U;
            _obj1.submit();
        }
        else if(_obj1.action){
            if(_obj1.action.indexOf(U) > -1){
                _obj1.action=U;
                _obj1.submit();
            }
            else{
                _obj1.href=U;
            }
        
        }else{
            _obj1.href=U;
        }
    }else{
        _obj1.href=U;
    }
    
    
    return false;
}

//----------------------------------------------------------------------------------------
//----------------------------- PRODUCT MATCH / UNMATCH FUNCTIONS ----------------------------------
function addProductMatchValue(myObject)
{    
    if(myObject.checked == true)
    {AjaxCall("/admin/matching/product_matching_array_add.php","prodID="+myObject.value,"","");}
    else
    {AjaxCall("/admin/matching/product_matching_array_remove.php","prodID="+myObject.value,"","");}
}

function clearMatchArray()
{
   //CLEAR SELECT BOXES
   var field = document.matchForm.matchCheck;
   for (i = 0; i < field.length; i++)
   {field[i].checked = false ;}
    
   AjaxCall("/admin/matching/product_matching_array_clear.php","","","");
   alert("Matching data cleared.");
}

function matchProducts(currentURL)
{
    var xmlhttp = createXMLHttp();
    xmlhttp.open("POST","/admin/matching/product_matching_process.php",false);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send("refererURL="+currentURL);
    
    //alert(xmlhttp.responseText);
    
   document.getElementById("matchButton").disabled = true;
   
   if(xmlhttp.responseText == "empty")
   {
        alert("No products in selection.");
        document.getElementById("matchButton").disabled = false;
   }
   else
   {
        window.location = xmlhttp.responseText;
   }   
}
//----------------------------------------------------------------------------------------
function TakeAction(actionID,productName,prodID)
{   
    switch(actionID)
    {
        case "1":
           var refererURL = escape(document.location);
           var completeURL = document.getElementById("tellafriend").value + "?URL=" + refererURL + "&prodName=" + productName;
           var popupWidth = 470;var popupHeight = 510;
           var screenW = screen.width;var screenH = screen.height;
           var xpos = ((screenW/2)-(popupWidth/2));var ypos = ((screenH/2)-(popupHeight/2));
           window.open(completeURL,'_new','left='+xpos+',top='+ypos+',width='+popupWidth+',height='+popupHeight+',toolbar=0,resizable=0');
           document.getElementById("myAction").selectedIndex = 0;
        break;
        case "2":          
           var completeURL = document.getElementById("printthispage").value + "?prodID=" + prodID;
           var popupWidth = 800;var popupHeight = 600;
           var screenW = screen.width;var screenH = screen.height;
           var xpos = ((screenW/2)-(popupWidth/2));var ypos = ((screenH/2)-(popupHeight/2));
           window.open(completeURL,'_new','left='+xpos+',top='+ypos+',width='+popupWidth+',height='+popupHeight+',toolbar=0,resizable=0');
           document.getElementById("myAction").selectedIndex = 0;
        break;        
    }   
}

//----------------------------------------------------------------------------------------
function enlargeImage()
{   
           var picURL = document.getElementById("enlargeURL").value;
           picURL = picURL.slice(0, -4)+"400/"
           var prodName = document.getElementById("prodName").value;           
           var refererURL = escape(document.location);
           var completeURL = "/products_actions/enlargeImage.php?ImageURL="+picURL+"&prodName="+prodName;
           var popupWidth = 400;var popupHeight = 400;
           var screenW = screen.width;var screenH = screen.height;
           var xpos = ((screenW/2)-(popupWidth/2));var ypos = ((screenH/2)-(popupHeight/2));
           window.open(completeURL,'_new','left='+xpos+',top='+ypos+',width='+popupWidth+',height='+popupHeight+',toolbar=0,resizable=0');
        
}

//----------------------------------------------------------------------------------------
function sendTellaFriend()
{
    if(document.getElementById("yourName").value != "")
     {if(document.getElementById("yourFriendName").value != "")
       {if(document.getElementById("yourFriendEmail").value != "" && IsEmail(document.getElementById("yourFriendEmail").value))
            {
                document.getElementById("sendButton").disabled = true;
                frmTellAFriend.submit();
            }
       else{alert("Please supply valid email address for your friend.");}         
     }else{alert("Please supply your friend's name.");}    
    }else{alert("Please supply your name.");}
}
function product_console(productid){

   
           var refererURL = escape(document.location);
           var completeURL = "/products_actions/product_console.php?id=" + productid;
           var screenW = screen.width;
           var screenH = screen.height;
           var popupWidth =  900; //screenW-50;
           var popupHeight = 700; //screenH-50;
           var xpos = ((screenW/2)-(popupWidth/2));var ypos = ((screenH/2)-(popupHeight/2));
           window.open(completeURL,'_new','left='+xpos+',top='+ypos+',width='+popupWidth+',height='+popupHeight+',toolbar=0,resizable=0,scrollbars=1');


}
function non(){}
//----------------------------------------------------------------------------------------
function redirect_attribute(obj){

    var selected_value = obj[obj.selectedIndex].value;
    
    obj.disabled = true;
    
    location.href = selected_value;
}
//----------------------------------------------------------------------------------------
function contactJump()
{
    if(document.getElementById("contactName").value != "")
      {if(document.getElementById("contactEmail").value != "" && IsEmail(document.getElementById("contactEmail").value))
          {if(document.getElementById("contactMessage").value != "")
              {if(document.getElementById("imageVerify").value != "")
                  {    
                     //AJAX CALL TO CHECK IMAGE VERIFICATION
                       RequestData = "verifyText=" + document.getElementById("imageVerify").value + "&name=" + document.getElementById("contactName").value + "&email=" + document.getElementById("contactEmail").value + "&msg=" + document.getElementById("contactMessage").value;
                       Path = "/general_content/image_verify.php";
                       var xmlhttp = createXMLHttp();
                       xmlhttp.open("POST",Path,false);
                       xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                       xmlhttp.send(RequestData);                   
                       
                       if(xmlhttp.responseText == "error")
                       {
                            alert("Incorrect Verification Text. Please re-enter.");
                            document.getElementById("imageVerify").value = "";
                            document.getElementById("imageVerify").focus();
                       }
                       else
                       {
                            window.location = "/general_content/contactus_thankyou.php";
                       }                    
                  }else{alert("Please verify the image code.");} 
              }else{alert("Please supply your query.");}            
          }else{alert("Please supply a valid e-mail address.");}        
      }else{alert("Please supply your name.");}
}
function showContactJump()
{
    if(document.getElementById("askjump").style.display == "block")
    {
        document.getElementById("askjump").style.display = "none";
    }
    else
    {
        document.getElementById("askjump").style.display = "block";
    }
}
//----------------------------------------------------------------------------------------
function booksearch()
{
    if(document.getElementById("bookISBN").value != "")
    {window.location = "/search/" + escape(document.getElementById("bookISBN").value) + "/books/669/";}
    else
    {if(document.getElementById("booktitle").value != "" && document.getElementById("bookauthor").value == "")
        {window.location = "/search/" + escape(document.getElementById("booktitle").value) + "/books/669/";}
        else
        {if(document.getElementById("bookauthor").value != "" && document.getElementById("booktitle").value == "")
            {window.location = "/search/" + escape(document.getElementById("bookauthor").value) + "/books/669/";}
            else
            {if(document.getElementById("bookauthor").value != "" && document.getElementById("booktitle").value != "")
                {window.location = "/search/" + escape(document.getElementById("booktitle").value)+ "/books/669/" + "kw__"+escape(document.getElementById("bookauthor").value);}
                else
                {document.getElementById("booktitle").focus();}                
            }        
        }        
    }
}
function resetBgColor()
{
    document.getElementById("booktitle").style.background = "#FFFFFF";
    document.getElementById("bookISBN").style.background = "#FFFFFF";
    document.getElementById("bookauthor").style.background = "#FFFFFF";
}
//----------------------------------------------------------------------------------------
function carsearch()
{
    var SelectObject = document.getElementById("carmake").selectedIndex;
    var selected_text = document.getElementById("carmake").options[SelectObject].text;

    if(SelectObject != 0 && SelectObject != 1)
    {if(document.getElementById("carmodel").value == "" && document.getElementById("caryear").value == "")
        {window.location = "/category/cars/1/brand__" + selected_text + "/";}
        else
        {if(document.getElementById("carmodel").value != "" && document.getElementById("caryear").value == "")
            {window.location = "/category/cars/1/brand__" + selected_text + "/kw__" + document.getElementById("carmodel").value;}
            else
            {if(document.getElementById("carmodel").value == "" && document.getElementById("caryear").value != "")
              {window.location = "/category/cars/1/brand__" + selected_text + "/kw__" + document.getElementById("caryear").value;}
              else
              {window.location = "/category/cars/1/brand__" + selected_text + "/kw__" + document.getElementById("carmodel").value + "__" + document.getElementById("caryear").value;}
            }
        }
    }
    else
    {document.getElementById("carmake").style.background = "#F0F0F0";}
}
//----------------------------------------------------------------------------------------
function addOption(selectbox,text,value)
{
       var mySelOption = document.createElement("OPTION");
       mySelOption.text = text;
       mySelOption.value = value;
       selectbox.options.add(mySelOption);
}
//----------------------------------------------------------------------------------------
function propertyGetData(catID,Type,Province,Suburb)
{
    //alert(catID + " - " + Type + " - " + Province);
    
    if(catID != 0)
    {
        //AJAX CALL
        var RequestData = "catID=" + catID + "&qType=" + Type + "&qProvince=" + Province + "&qSuburb=" + Suburb;
        var Path = "/template_objects/search_within_property_process.php";

        var xmlhttp = createXMLHttp();
        xmlhttp.open("POST",Path,false);
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlhttp.send(RequestData); 
    }
    
    if(Type == 1)//POPULATE PROVINCES
    {
        if(catID != 0)
        {
            document.getElementById("propSuburb").options.length = 0;
            document.getElementById("suburbRow").style.display = "none";
            document.getElementById("pricerangeRow").style.display = "none";
            document.getElementById("provinceRow").style.display = "inline";
            document.getElementById("propProvince").options.length = 0;            
            document.getElementById("minPrice").value = 0;
            document.getElementById("maxPrice").value = 0;
            addOption(document.getElementById("propProvince"),"Select Province","0");
            addOption(document.getElementById("propProvince"),"---------------","0");
            var result_array = (xmlhttp.responseText).split("^||^");
            
            for (var k=0; k < result_array.length;++k)
            {
                var result_array_2 = (result_array[k]).split("|^^|");
                addOption(document.getElementById("propProvince"),result_array_2[1], result_array_2[0]);                               
            } 
            document.getElementById("propProvince").focus();      
        }
    }
    
    if(Type == 2)//POPULATE SUBURBS
    {
        if(Province != 0)
        {
            document.getElementById("propSuburb").options.length = 0;
            document.getElementById("suburbRow").style.display = "inline";
            document.getElementById("pricerangeRow").style.display = "inline";            
            addOption(document.getElementById("propSuburb"),"Select Suburb","0");
            addOption(document.getElementById("propSuburb"),"---------------","0");
            var result_array = (xmlhttp.responseText).split("^||^");
            
            for (var k=0; k < result_array.length;++k)
            {
                var result_array_2 = (result_array[k]).split("|^^|");
                addOption(document.getElementById("propSuburb"),result_array_2[1], result_array_2[0]);                               
            }  
        
            document.getElementById("propSuburb").focus(); 
        }      
    }
    
    if(Type == 2 || Type == 3)
    {
            //GET PRICE RANGES
                var RequestData = "catID=" + catID + "&qType=3&qProvince=" + Province + "&qSuburb=" + Suburb;
                var Path = "/template_objects/search_within_property_process.php";
                
                //alert(RequestData);

                var xmlhttp = createXMLHttp();
                xmlhttp.open("POST",Path,false);
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xmlhttp.send(RequestData);        
                //alert(xmlhttp.responseText);
                var result_array = (xmlhttp.responseText).split("^||^");
                document.getElementById("minPrice").value = result_array[0];
                document.getElementById("maxPrice").value = result_array[1];    
    }    
}
function propertySearch()
{
    if(document.getElementById("propType").value != 0)
    {
        var minPrice; 
        var maxPrice;
        var SelectObject = document.getElementById("propType").selectedIndex;
        var selected_text = document.getElementById("propType").options[SelectObject].text;
        var words = selected_text.split(" "); 

        if(document.getElementById("propProvince").value == 0)
        {window.location = "/category/property/" + words[0].toLowerCase() + "-property/" + document.getElementById("propType").value + "/";}
        else
        {if(document.getElementById("propProvince").value != 0 && document.getElementById("propSuburb").value == 0)
            {if(document.getElementById("priceFrom").value != "" || document.getElementById("priceTo").value != "")
                {if((IsNumber(document.getElementById("priceFrom").value) && IsNumber(document.getElementById("priceTo").value)) && (document.getElementById("priceFrom").value*1 <= document.getElementById("priceTo").value*1))
                    {if((document.getElementById("priceFrom").value*1 < document.getElementById("minPrice").value*1) || (document.getElementById("priceFrom").value*1 > document.getElementById("maxPrice").value*1)){minPrice = document.getElementById("minPrice").value*1;}else{minPrice = document.getElementById("priceFrom").value;}
                     if((document.getElementById("priceTo").value*1 > document.getElementById("maxPrice").value*1) || (document.getElementById("priceTo").value*1 < document.getElementById("minPrice").value*1)){maxPrice = document.getElementById("maxPrice").value*1;}else{maxPrice = document.getElementById("priceTo").value;}
                     window.location = "/category/property/" + words[0].toLowerCase() + "-property/" + document.getElementById("propType").value + "/province__" + document.getElementById("propProvince").value + "/pricerange__" + minPrice + "_" + maxPrice;}
                    else
                    {alert("Price range needs to be numeric only, and the minimum price needs to be smaller than the maximum price.");}
                }
                else
                {window.location = "/category/property/" + words[0].toLowerCase() + "-property/" + document.getElementById("propType").value + "/province__" + document.getElementById("propProvince").value;}
            }
            else
            {if(document.getElementById("propProvince").value != 0 && document.getElementById("propSuburb").value != 0)
                {if(document.getElementById("priceFrom").value != "" || document.getElementById("priceTo").value != "")
                    {if((IsNumber(document.getElementById("priceFrom").value) && IsNumber(document.getElementById("priceTo").value)) && (document.getElementById("priceFrom").value*1 <= document.getElementById("priceTo").value*1))
                        {if((document.getElementById("priceFrom").value*1 < document.getElementById("minPrice").value*1) || (document.getElementById("priceFrom").value*1 > document.getElementById("maxPrice").value*1)){minPrice = document.getElementById("minPrice").value*1;}else{minPrice = document.getElementById("priceFrom").value;}
                         if((document.getElementById("priceTo").value*1 > document.getElementById("maxPrice").value*1) || (document.getElementById("priceTo").value*1 < document.getElementById("minPrice").value*1)){maxPrice = document.getElementById("maxPrice").value*1;}else{maxPrice = document.getElementById("priceTo").value;}
                         window.location = "/category/property/" + words[0].toLowerCase() + "-property/" + document.getElementById("propType").value + "/province__" + document.getElementById("propProvince").value + "/suburb__" + document.getElementById("propSuburb").value + "/pricerange__" + minPrice + "_" + maxPrice;                            
                        }
                        else
                        {alert("Price range needs to be numeric only, and the minimum price needs to be smaller than the maximum price.");}
                    }
                    else
                    {window.location = "/category/property/" + words[0].toLowerCase() + "-property/" + document.getElementById("propType").value + "/province__" + document.getElementById("propProvince").value + "/suburb__" + document.getElementById("propSuburb").value;}
                }
            }  
        }
    }
    else
    {document.getElementById("propType").focus();}
}
//---------------------Signup-----------------------//
function signup()
{
    if(document.getElementById("storeName1AbC").value != "")
    {if(document.getElementById("storeURL2CdE").value != "" && document.getElementById("storeURL2CdE").value.indexOf('http://') != -1 && document.getElementById("storeURL2CdE").value.length > 10)
                {if(document.getElementById("storeContact5LmN").value != "")
                    {if(document.getElementById("storeContact7RsT").value != "" && document.getElementById("storeContact7RsT").value.length >= 7)
                        {if(document.getElementById("storeEmail8UvW").value != "" && IsEmail(document.getElementById("storeEmail8UvW").value))
                                {
                                    document.getElementById("signupButtonDv6000Q1").disabled = true;
                                    document.frmSignup.submit();
                                }
                                else
                                {
                                    document.getElementById("storeEmail8UvW").style.background = "#e4f5ff";
                                    document.getElementById("errorMsgP3O4U7").innerHTML = "Invalid Email Address.";
                                    document.getElementById("storeEmail8UvW").focus();                                     
                                }                                
                            }else{
                                document.getElementById("storeContact7RsT").style.background = "#e4f5ff";
                                document.getElementById("errorMsgP3O4U7").innerHTML = "Invalid Phone Number.";
                                document.getElementById("storeContact7RsT").focus(); 
                            }                             
                    }else{
                        document.getElementById("storeContact5LmN").style.background = "#e4f5ff";
                        document.getElementById("errorMsgP3O4U7").innerHTML = "Invalid Contact Person.";
                        document.getElementById("storeContact5LmN").focus();            
                    }                    
        }else{
            document.getElementById("storeURL2CdE").style.background = "#e4f5ff";
            document.getElementById("errorMsgP3O4U7").innerHTML = "Invalid Website Address.";
            document.getElementById("storeURL2CdE").value = "http://";
            document.getElementById("storeURL2CdE").focus();
        }        
    }else{
        document.getElementById("storeName1AbC").style.background = "#e4f5ff";
        document.getElementById("errorMsgP3O4U7").innerHTML = "Invalid Store Name.";
        document.getElementById("storeName1AbC").focus();}
}
//---------------------Signup-----------------------//

//---------------------REVIEWS-----------------------//
var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
var calunit=ns? "" : "px"
adCount=0;

function initAd()
{
	if(!ns && !ie && !w3) return;
	if(ie)		adDiv=eval('document.all.sponsorAdDiv.style');
	else if(ns)	adDiv=eval('document.layers["sponsorAdDiv"]');
	else if(w3)	adDiv=eval('document.getElementById("sponsorAdDiv").style');
         adDiv.display="block";
	    showAd();
}
function showAd()
{
	if (ie){documentWidth  =truebody().offsetWidth/2+truebody().scrollLeft-20;
	documentHeight =truebody().offsetHeight/2+truebody().scrollTop-20;}	
	else if (ns){documentWidth=window.innerWidth/2+window.pageXOffset-20;
	documentHeight=window.innerHeight/2+window.pageYOffset-20;} 
	else if (w3){documentWidth=self.innerWidth/2+window.pageXOffset-20;
	documentHeight=self.innerHeight/2+window.pageYOffset-20;} 
	adDiv.left=documentWidth-200+calunit;adDiv.top =documentHeight-200+calunit;
}
function closeAd()
{
    adDiv.display="none";
}

function saveReview()
{
        var radioValue = "";
        for( i = 0; i < document.frmReview.reviewRecommend.length; i++ )
        {
        if( document.frmReview.reviewRecommend[i].checked == true )
        radioValue = document.frmReview.reviewRecommend[i].value;
        }
            
       var Score1 = document.getElementById("starRating_1").value;
       var Score2 = document.getElementById("starRating_2").value;
       var Score3 = document.getElementById("starRating_3").value;
       var Score4 = document.getElementById("starRating_4").value;

        if(radioValue != "")
        {
           var rURL = window.location.href;
                                 
           RequestData = "StoreID="+document.getElementById("reviewStoreID").value+"&ease="+Score1+"&avail="+Score2+"&deliver="+Score3+"&care="+Score4+"&recomm="+radioValue;
           
           Path = "/merchants/storereviews/save_review.php";
           
           var xmlhttp = createXMLHttp();
           xmlhttp.open("POST",Path,false);
           xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
           xmlhttp.send(RequestData);   
           
           if(xmlhttp.responseText == "success")
           {
                alert("Thanks. Your review was successfully submitted."); window.location = rURL; 
           }
           else
           {
                alert("An error occurred. Please retry submitting your review.")
           }                    
       }
       else
       {
            alert("Would you recommend this store?");
       }
}
function showProductReviewBox()
{
	var state = document.getElementById("new_product_review").style.display;
	if(state == "none")
	{
	    document.getElementById("new_product_review").style.display = "inline";
	    document.getElementById("review_text").focus();
	}
	else
	{
		document.getElementById("new_product_review").style.display = "none";
	}
}
function reportReview(rid)
{
   var psrc = window.location.href;
   RequestData = "rid="+rid+"&psrc="+psrc;
   Path = "/products/report_review_process.php";

   var xmlhttp = createXMLHttp();
   xmlhttp.open("POST",Path,false);
   xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   xmlhttp.send(RequestData);  
   if(xmlhttp.responseText == "success")
   {
        alert("Thank you for reporting abuse."); 
   }
   else
   {
        alert("An error occurred. Please retry reporting the review.")
   }
}
function saveProductReview()
{
       var Score1 = document.getElementById("starRating_1").value;
       var reviewID = document.getElementById("review_ID").value;
       if(Score1 > 0)
       {
           if(document.getElementById("review_text").value != "" && document.getElementById("review_text").value.length < 230)
           {
                var neededChars = (230 - document.getElementById("review_text").value.length);
                alert("Reviews must be at least 230 characters in length.\nYou need "+neededChars+" more characters.");
           }
           else
           {
               var rURL = window.location.href;
               if(rURL.indexOf("#reviews") > 0){rURL = rURL.substr(0,rURL.indexOf("#reviews"));}
               
               RequestData = "pid="+document.getElementById("review_productID").value+"&score="+Score1+"&review="+escape(document.getElementById("review_text").value)+"&reviewID="+reviewID;
               Path = "/products/compare_reviews_process.php";
               
               document.getElementById("btnProdReview").disabled = true;
                   
               var xmlhttp = createXMLHttp();
               xmlhttp.open("POST",Path,false);
               xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
               xmlhttp.send(RequestData);  
               alert(xmlhttp.responseText);
               if(xmlhttp.responseText == "success")
               {
                    alert("Thank you. Your review was successfully submitted."); 
                    window.location = rURL; 
               }
               else
               {
                    alert("An error occurred. Please retry submitting your review.");
                    document.getElementById("btnProdReview").disabled = false;
               }
           }
       }
       else
       {
            alert("Please rate this product.");
       }                    
}

function truebody()
{
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function writeReview(storeName,StoreID)
{
    document.getElementById("reviewStoreName").innerHTML = storeName;
    document.getElementById("reviewStoreID").value = StoreID;  
    initAd();
}

function showReviewBox(signedIn,ease,avail,time,care)
{
    if(!signedIn)
    {
        self.parent.tb_force_open('<strong>Jump.co.za members area</strong>','/users/sign_in.php?pub_action=review&amp;keepThis=true&amp;TB_iframe=true&amp;height=300&amp;width=500');
    }
    else
    {
        var boxstate = document.getElementById("divRating").style.display;
        
        if(boxstate == "none")
        {
            document.getElementById("divRating").style.display = "block";
            setRating(1,ease);setRating(2,avail);setRating(3,time);setRating(4,care);
        }
        
        if(boxstate == "block")
        {
            document.getElementById("divRating").style.display = "none";
        }
    }
    
}

function reviewRating(starGroup,starNo)
{
    var x; var y;
    for(x=1;x<=starNo;x++)
    {
        document.getElementById("star_"+starGroup+"_"+x).src = "/images/star_on.gif";
    }
    for(y=5;y>starNo;y--)
    {
        document.getElementById("star_"+starGroup+"_"+y).src = "/images/star_off.gif";
    }
    
    starNo = parseInt(starNo);    
    switch (starNo)
    {
        case 0: document.getElementById("ratingText_"+starGroup).value = ""; break;
        case 1: document.getElementById("ratingText_"+starGroup).value = "Very bad"; break;
        case 2: document.getElementById("ratingText_"+starGroup).value = "Bad"; break;
        case 3: document.getElementById("ratingText_"+starGroup).value = "Good"; break;
        case 4: document.getElementById("ratingText_"+starGroup).value = "Very good"; break;
        case 5: document.getElementById("ratingText_"+starGroup).value = "Excellent"; break;
    }    
}
function reviewRatingReset(starGroup,starNo)
{ 
    reviewRating(starGroup,document.getElementById("starRating_"+starGroup).value);
}
function setRating(starGroup,starNo)
{
   document.getElementById("starRating_"+starGroup).value = starNo;
   reviewRating(starGroup,document.getElementById("starRating_"+starGroup).value);
}

function ReviewExpand(RevID)
{
    if(document.getElementById("rev_"+RevID).style.height != "")
    {
        document.getElementById("read_"+RevID).innerHTML = "Read less...";
        document.getElementById("rev_"+RevID).style.height = "";
        
    }
    else
    {
        document.getElementById("rev_"+RevID).style.height = "58px";
        document.getElementById("read_"+RevID).innerHTML = "Read more...";
    }
}
function imposeMaxLength(MaxLen)
{
  if(document.getElementById("review_text").value.length >= MaxLen)
  {
    alert(MaxLen+" characters only.");
    document.getElementById("review_text").value = document.getElementById("review_text").value.substr(0,MaxLen+1);
  }
}
function resendValidation()
{
     Path = "/users/validation_resend.php";
     RequestData = "";
     var xmlhttp = createXMLHttp();
     xmlhttp.open("POST",Path,false);
     xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     xmlhttp.send(RequestData); 
     
     if(xmlhttp.responseText == "success")
     {
        alert("Thank you. The validation e-mail was sent.");
     }
     else
     {
        alert("An error occured while trying to resend your validation e-mail. Please contact info@jump.co.za to have this resolved.")
     }
}
//-----------------------------------PROFILE-------------------------------------------
function profileSNupdate(state)
{
    if(state == 1)
    {
        document.getElementById("origSN").style.display = "none";   
        document.getElementById("newSN").style.display = "inline";   
        document.getElementById("snChange").style.display = "none";   
        document.getElementById("snSave").style.display = "inline";  
        document.getElementById("ScreenNameR5U78").focus(); 
    }
    if(state == 2)
    {
         document.getElementById("snSaveBtn").disabled = true;
         document.getElementById("snCancelBtn").disabled = true;
         
         Path = "/users/profile_screen_name_process.php";
         RequestData = "sn=" + document.getElementById("ScreenNameR5U78").value;
         var xmlhttp = createXMLHttp();
         xmlhttp.open("POST",Path,false);
         xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
         xmlhttp.send(RequestData);
         
         if(xmlhttp.responseText.substring(0,4) == "ERR:")
         {
            alert(xmlhttp.responseText.substring(4,xmlhttp.responseText.length));
            document.getElementById("ScreenNameR5U78").value = "";
            document.getElementById("ScreenNameR5U78").focus();
            document.getElementById("snSaveBtn").disabled = false;
            document.getElementById("snCancelBtn").disabled = false;
            return false;
         }
         else
         {
            window.location = xmlhttp.responseText;
         }
    }
    if(state == 3)
    {
        document.getElementById("origSN").style.display = "inline";   
        document.getElementById("newSN").style.display = "none";   
        document.getElementById("snChange").style.display = "inline";   
        document.getElementById("snSave").style.display = "none";  
        document.getElementById("ScreenNameR5U78").value = ""; 
    }    
}
function profilePWupdate(state)
{
    if(state == 1)
    {
        document.getElementById("updatePass").style.display = "inline";
        document.getElementById("pwChange").style.display = "none";   
        document.getElementById("pwSave").style.display = "inline";  
        document.getElementById("origPW").focus();
    }
        if(state == 2)
    {
         document.getElementById("pwSaveBtn").disabled = true;
         document.getElementById("pwCancelBtn").disabled = true;
         
         Path = "/users/profile_password_process.php";
         RequestData = "pw="+document.getElementById("origPW").value+"&npw="+document.getElementById("newPW").value+"&npwc="+document.getElementById("newPWconf").value;
         var xmlhttp = createXMLHttp();
         xmlhttp.open("POST",Path,false);
         xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
         xmlhttp.send(RequestData);
         
         if(xmlhttp.responseText.substring(0,4) == "ERR:")
         {
            alert(xmlhttp.responseText.substring(4,xmlhttp.responseText.length));
            document.getElementById("origPW").value = "";
            document.getElementById("newPW").value = "";
            document.getElementById("newPWconf").value = "";
            document.getElementById("origPW").focus();
            document.getElementById("pwSaveBtn").disabled = false;
            document.getElementById("pwCancelBtn").disabled = false;
            return false;
         }
         else
         {
            if(xmlhttp.responseText == "success")
            {
                document.getElementById("curPW").style.color = "green";
                document.getElementById("curPW").innerHTML = "[succesfully updated]";
                profilePWupdate(3);
                return false;
            }
         }
    }
    if(state == 3)
    {
        document.getElementById("updatePass").style.display = "none";
        document.getElementById("pwChange").style.display = "inline";   
        document.getElementById("pwSave").style.display = "none";
        document.getElementById("origPW").value = "";  
        document.getElementById("newPW").value = "";  
        document.getElementById("newPWconf").value = "";
        document.getElementById("pwSaveBtn").disabled = false;
        document.getElementById("pwCancelBtn").disabled = false;  
    }    
}
function profileNLupdate()
{
    Path = "/users/profile_newsletter_process.php";
    RequestData = "s=1";
    var xmlhttp = createXMLHttp();
    xmlhttp.open("POST",Path,false);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(RequestData);
    
    if(xmlhttp.responseText.substring(0,4) == "ERR:")
    {
        alert(xmlhttp.responseText.substring(4,xmlhttp.responseText.length));
    }
    else
    {
        document.getElementById("origNL").innerHTML = xmlhttp.responseText;
    }
}
function profileRemove(type,id,src)
{
    Path = "/users/profile_remove_process.php";
    RequestData = "t="+type+"&id="+id+"&src="+src;
    var xmlhttp = createXMLHttp();
    xmlhttp.open("POST",Path,false);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
    if(type == 3)
    {
        var confirm = window.confirm("Are you sure to want delete this review?");	
        if (confirm){xmlhttp.send(RequestData);}
    }
    else
    {
        xmlhttp.send(RequestData);
    }
    
    if(src != "")
    {
        if(xmlhttp.responseText.substring(0,4) == "ERR:")
        {
           alert(xmlhttp.responseText.substring(4,xmlhttp.responseText.length));
        }
        else
        {
            window.location = xmlhttp.responseText;
        }
    }
    else
    {
        if(xmlhttp.responseText == "success")
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

function load_wia(path)
{
//    if(load_secondary_data){
  //      var t = setTimeout("show_loading()", 200)
//    }
    //document.getElementById("loading").style.display = "block";
  
    var uniqueid = new Date().getTime()
    
    //path = path + "&ts=" + uniqueid;
    //last_obj = var_obj
    
	var xmlhttp = createXMLHttp();
	//xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.onreadystatechange=function(){ wia_stateChanged(xmlhttp); };

	xmlhttp.open("GET",path,true);
	xmlhttp.send(null);
	
}

function wia_stateChanged(xmlhttp){

	if (xmlhttp.readyState!=4)
		return;

	if (xmlhttp.readyState==4 && xmlhttp.status == 200){ 
	    // DONE
		//obj_loading.style.display = "none";
		//obj = document.getElementById(var_obj);
		//obj.innerHTML = xmlhttp.responseText
		//alert(xmlhttp.responseText);
		
		var res = xmlhttp.responseText + "";
		if(res.length > 0){
		    arr = res.split("\n");
		    
		    //alert(arr.length);
		    
		    for (x in arr){
		        if(arr[x].indexOf("=") > -1){
		            
		            var id = arr[x].substring(0,arr[x].indexOf("="));
		            var price = arr[x].substring(arr[x].indexOf("=")+1);
		            
		            obj = document.getElementById("price_" + id);
		            
		            //alert(obj);
		            
		            if(obj){
		                obj.innerHTML = price;
		                //alert(id + "~" + price);
		            }
		            else{
		                
		            }
		            
		            //alert(id + "!" + price);
		        }
		        //alert(arr[x]);
		    }
		    
		}
		
		if(wantitall_string.length > 0){
		
		    arr = wantitall_string.split("~");
		    
		    for (x in arr){
		    
		        tt = arr[x].split("==");
		        
		        obj = document.getElementById("price_" + tt[0]);
		        
		        if(obj){
		            if(obj.innerHTML.indexOf("price_loader") > -1){
		                obj.innerHTML = "";
		            }
		        }
		    
		    
		    }
		
	    }
		
		//document.getElementById("loading").style.display = "none";

		
	}

}

var wantitall_string = "";

function ajax_update_prices(id_string, decimals){

    if(!decimals)
        decimals = 0;


    path = "/includes/wantitall_prices.php?decimals="+ decimals +"&id_string=" + escape(id_string);
    //document.write(path);
    wantitall_string = id_string;
    load_wia(path);
}



function match_selected(){
    
    var p_ids = "";
    var m_ids = "";
 
    for(y=1;y<20;y++){
        if(document.getElementById("p_ids_" + y)){
            if(document.getElementById("p_ids_" + y).checked){
               p_ids = p_ids + "," + document.getElementById("p_ids_" + y).value; 
            }
        }
    }
    
    for(y=1;y<20;y++){
        if(document.getElementById("m_ids_" + y)){
            if(document.getElementById("m_ids_" + y).checked){
               m_ids = m_ids + "," + document.getElementById("m_ids_" + y).value; 
            }
        }
    }

    if(p_ids.length > 0){
        p_ids = p_ids.substring(1);
    }

    if(m_ids.length > 0){
        m_ids = m_ids.substring(1);
    } 
//    var ids = "";
//    for (i = 0; i < ids_obj.length; i++){
//        alert(ids_obj[i].value);
//        //if(ids_obj[i].checked){
//          //  ids = ids + ids_obj[i].value;
//        //}
//    }

//   

    if(p_ids.length > 0 || m_ids.length > 0){
        var path = "/products/match.php?p_ids="+ escape(p_ids) +"&m_ids=" + escape(m_ids);
        location.href = path;
    }

    
}

function submit_insurance(){

    var obj = document.getElementById("frm_insurance");
    
    var msg = "";
    
    if(obj.title[obj.title.selectedIndex].value == ""){
        msg = msg + "* Please select a title\n";
    }
    
    if(obj.first_name.value.length <= 3){
        msg = msg + "* Please enter a valid First Name\n";
    }

    if(obj.last_name.value.length <= 3){
        msg = msg + "* Please enter a valid Last Name\n";
    }

    if(obj.id_number.value.length < 13){
        msg = msg + "* Please enter a valid ID Number\n";
    }
    
    if(obj.cell_number.value.length < 10){
        msg = msg + "* Please enter a valid Cell Number\n";
    }

    if(obj.email.value.length < 3){
        msg = msg + "* Please enter a valid Email Address\n";
    }else{
        if(!IsEmail(obj.email.value)){
            msg = msg + "* Please enter a valid Email Address\n";
        }
    }


    if(msg != ""){
        alert("There was a problem with your details:\n\n" + msg + "\nPlease correct the above mentioned fields and re-submit your form");    
        return false;    
    }else{
        obj.quote_btn.value = "Loading...";
        obj.quote_btn.disabled = true;
        return true;
    }
}
function ObjectAction_stateChanged(xmlhttp)
{
    if (xmlhttp.readyState!=4)return;
	if (xmlhttp.readyState==4 && xmlhttp.status == 200)
	{
	    document.getElementById("newsletter_signup").innerHTML = xmlhttp.responseText;
	}
}
function newsletter_signup()
{
    if(IsEmail(document.getElementById("emailAddress").value))
    {    
        
        RequestData = "e="+document.getElementById("emailAddress").value+"&v="+document.getElementById("verify").value;
        document.getElementById("newsletter_signup").style.background = "none";
        document.getElementById("newsletter_signup").innerHTML = "<div class='newsletter_ajax_loading'><!----></div>";
        Path = "/newsletter/signup_process.php";
        var xmlhttp = createXMLHttp();
        xmlhttp.onreadystatechange = function(){ObjectAction_stateChanged(xmlhttp);};
        xmlhttp.open("POST",Path,true);
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlhttp.send(RequestData);    
    }
    else
    {
        alert("Please enter a valid e-mail address.");
    }
}


