
var activeRequests=new Array()
var msgs=new Array()



function Request(ReqName){
	this.active=false;
	this.url='';
	this.response='';
	this.debug=false;
	this.req=null;
	this.name=ReqName;
	this.oncomplete=null;
	this.XMLErrorCount=0;
	this.MaxError=10;
	this.XMLEnabled=CheckXML()
	//this.XMLEnabled=false
	this.requestindex=activeRequests.length 
	activeRequests[activeRequests.length]=this
}


Request.prototype.send=SendRequest
Request.prototype.writeLog=writeLog
Request.prototype.isActive=function (){return this.active}
Request.prototype.resetErrCount=function (){XMLErrorCount=0}
Request.prototype.sendUsingIframe=sendUsingIframe

function writeLog(Msg){
	if(!this.debug)
		return;
	if(!document.getElementById("ReqDebug"))
		CreateDebug()
	
	document.getElementById("ReqDebug").value+='\n'+this.name+":"+Msg
	
	

}
function CreateDebug(){
	var DebugText=document.createElement("textarea")
	DebugText.id="ReqDebug"
	DebugText.style.width="100%"
	DebugText.style.height="300px"
	document.body.appendChild(DebugText)

}


function SendRequest() 
{
	if (arguments.length>0)
		this.url=arguments[0]
	
	if (this.url=='')
		return false;
	
	if (this.active)
		return false;
		
	if (!this.XMLEnabled){
		this.sendUsingIframe(this.url)
		return true
		
	}
		
    
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        this.req = new XMLHttpRequest();
        this.writeLog("getting url:"+this.url);
        this.req.onreadystatechange = ProcessRequests;       
        this.req.open('GET', this.url, true);
        this.active=true
        this.req.send(null);
        //branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
		this.req = new ActiveXObject("Microsoft.XMLHTTP");
		this.req.onreadystatechange = ProcessRequests;        
        if (this.req) {
			this.writeLog("getting url:"+this.url);
            this.req.open("GET", this.url, true);
            this.active=true
            this.req.send();
        }
    }
    return true;
}

function ProcessRequests(){
	for (j=0;j<activeRequests.length;j++){
		if(activeRequests[j].req!=null){
			if (activeRequests[j].req.readyState){
				if (activeRequests[j].req.readyState == 4  ) {
					activeRequests[j].writeLog("Document Processed");
				    // only if "OK"
				    if (activeRequests[j].req.status == 200) {
						activeRequests[j].writeLog("Document OK");
						activeRequests[j].XMLErrorCount=0
						
				        activeRequests[j].response=activeRequests[j].req.responseText;
				        re = /<(.*)INFO\"/;
				        activeRequests[j].response=trim(activeRequests[j].response.replace(re,''))
				        re = /-->/;
				        activeRequests[j].response=activeRequests[j].response.replace(re,'')
				        activeRequests[j].writeLog("Response:\n"+activeRequests[j].response);
							
				    } else {
						activeRequests[j].XMLErrorCount++
				        if (activeRequests[j].XMLErrorCount>activeRequests[j].MaxError){
							alert("There was a problem retrieving the data");
				        }
				    }

						
						activeRequests[j].req=null
						activeRequests[j].active=false
						if (activeRequests[j].oncomplete!=null)
							//activeRequests[j].oncomplete
							window.setTimeout(activeRequests[j].oncomplete,50)

				}			
			}
		}
	}
}


function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
function CheckXML(){
	if (window.XMLHttpRequest) {
		return true; 
     //branch for IE/Windows ActiveX version
    }
    else if (window.ActiveXObject) {
		return true;
    }
    
    return false;

}

function sendUsingIframe(url){
	this.writeLog("Send Using Iframe")
	if (url.indexOf("?")>0)
	url+="&CallBack=requestCallback("+this.requestindex+",document.body.innerHTML)"
	this.writeLog("Send using URL:" +url)
	
	this.active=true
	CreateIFrame("iframeRequest_"+ this.name,url,200,200)
	this.writeLog("Iframe Created Waiting for a Response")
}
function requestCallback(requestIdx,Response){

	if (activeRequests[requestIdx]){
		activeRequests[requestIdx].writeLog("Iframe Response")
		activeRequests[requestIdx].response=Response
		activeRequests[requestIdx].writeLog("Response:\n"+Response)
		activeRequests[requestIdx].active=false
		if (activeRequests[requestIdx].oncomplete!=null)
			//activeRequests[requestIdx].oncomplete
			window.setTimeout(activeRequests[requestIdx].oncomplete,50)
		
	}

}



function CreateIFrame(id,url){

	var Framewidth=0
	var Frameheight=0
	
	if (arguments.length>2){
		Framewidth=arguments[2]
	}
	if (arguments.length>3){
		Frameheight=arguments[3]
	}
	
	if(!window.frames[id]){
	try{
			var iFrame = document.createElement("iframe");
			iFrame.setAttribute('id',id);
			iFrame.setAttribute('name',id);
			iFrame.style.width = Framewidth+"px";
			iFrame.style.height = Frameheight+"px";
			iFrame.src = url;
			createdframe = document.body.appendChild(iFrame);
			
			if (document.frames) {
				createdframe = document.frames[id];
			}
			
		}catch(e){
			var iframeHTML = '\<iframe id="' + id + '"';
			iframeHTML += ' style="border:0px; width:'+Framewidth+'px; height:'+Frameheight+'px;';
			iframeHTML += '"><\/iframe>';
			document.body.innerHTML += iframeHTML;
			iframe = new Object();
			iframe.document = new Object();
			iframe.document.location = new Object();
			iframe.document.location.createdframe = 
			document.getElementById(id);
			iframe.document.location.replace = 
			function(location) {
				this.iframe.src = location;
			}
		}	
	
	}
	else
	{
		window.frames[id].location.href=url
	}
	
	
}





function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}



var prodReq = new Request();
function GetProductData(){
if (SelectedProduct!='' && SelectedLang!=''){
    var url=dpath+'productlist.asp?Product='+SelectedProduct+'&lang='+SelectedLang
    url=url+'&uid='+ Date()
    prodReq.url=url
    prodReq.oncomplete='GetProdCallBack()'
    document.getElementById('productlistdetail').innerHTML='<img src="'+dpath+'Images/wait.gif" alt="Please Wait" border="0" align="absmiddle" />&nbsp;&nbsp;'+msgs[10]
    prodReq.send()
    }

}

function GetProdCallBack(){
    document.getElementById('productlistdetail').innerHTML=prodReq.response
}

function ProductIdonChange()
{
SelectedProduct=ProdSelObj.getActualValue()
GetProductData()
}
function LangIdonChange()
{
SelectedLang=LangSelObj.getActualValue()
GetProductData()
}

function doProductsdrop(){
droplist('productselect','productselecteditem')
droplist('langselect','langelecteditem',true)
}
function dolangdrop(){
droplist('productselect','productselecteditem',true)
droplist('langselect','langelecteditem')

}
function droplist(selectdiv,parent){

if (arguments.length>2){
    if (arguments[2]){
        if (document.getElementById(selectdiv)){
            document.getElementById(selectdiv).style.display='none'
        }
    }
    else
    {
         if (document.getElementById(selectdiv)){
            document.getElementById(selectdiv).style.display='block'
        }   
    }
    return
}

if (document.getElementById(selectdiv)){
    if (document.getElementById(selectdiv).style.display=='none')
    {
        if (document.getElementById(parent)){
            y=findPos(document.getElementById(parent))
            document.getElementById(selectdiv).style.top=y[1]+24
            document.getElementById(selectdiv).style.left=y[0]
        }
        document.getElementById(selectdiv).style.display='block'
    }
    else
    {
        document.getElementById(selectdiv).style.display='none'
    }

}


}

function SelectProd(Product,Image,desc){
SelectedProduct=Product
var h=new String();
h='<a style="vertical-align:top" class="selectitem" href="javascript:doProductsdrop()">'
h+= '<img alt="'+desc+'" src="'+Image+'" style="vertical-align:top" />'
h+= '<span class="selectitemlabel"  >'
h+= '<img src="'+dpath+'Images/blank.gif" height="20" width="5" />'
h+=  desc +'</span></a>'
h+='<a href="javascript:doProductsdrop()"><img style="border:none" height="20" width="17" src="'+dpath+'Images/combo_select.gif" /></a>'


document.getElementById('productselecteditem').innerHTML=h
droplist('productselect','productselecteditem',true)
GetProductData()
}

function SelectLang(Product,Image,desc){
SelectedLang=Product
var h=new String();
h='<a style="vertical-align:top" class="selectitem" href="javascript:dolangdrop()">'
h+= '<img alt="'+desc+'" src="'+Image+'" style="vertical-align:top" />'
h+= '<span class="selectitemlabel"  >'
h+= '<img src="'+dpath+'Images/blank.gif" height="20" width="5" />'
h+=  desc +'</span></a>'
h+='<a href="javascript:dolangdrop()"><img style="border:none" height="20" width="17" src="'+dpath+'Images/combo_select.gif" /></a>'


document.getElementById('langelecteditem').innerHTML=h
droplist('langselect','langelecteditem',true)
GetProductData()
}

function Expand(id){
    if (document.getElementById('div-'+id)){
        if (document.getElementById('div-'+id).style.display=='none'){
            document.getElementById('div-'+id).style.display='block'
            document.getElementById('img-'+id).src=dpath+'images/minus.gif'
            
        }   
        else
        {
            document.getElementById('div-'+id).style.display='none'  
            document.getElementById('img-'+id).src=dpath+'images/plus.gif'      
        }     
    }

}


var SAState= new Array("Eastern Cape", "Free State", "Gauteng", "Kwazulu-Natal", "Mpumalanga", "Northern Cape", "Northern Province","North-West","Western Cape")
var AUState= new Array("NSW", "QLD", "SA", "NT", "WA", "ACT", "VIC","TAS")
var USState= new Array("Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","District of Columbia","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virgin Islands","Virginia","Washington","West Virginia","Wisconsin","Wyoming")
var CAState= new Array("Alberta","British Columbia","Manitoba","New Brunswick","Newfoundland","Northwest Territories","Nova Scotia","Nunavut","Ontario","Prince Edward Island","Quebec","Saskatchewan","Yukon")
var INState= new Array("Andaman and Nicobar Islands","Andhra Pradesh","Arunachal Pradesh","Assam","Bihar","Chandigarh","Chhattisgarh","Dadra and Nagar Haveli","Daman and Diu","Delhi","Goa","Gujarat","Haryana","Himachal Pradesh","Jammu and Kashmir","Jharkhand","Karnataka","Kerala","Lakshadweep","Madhya Pradesh","Maharashtra","Manipur","Meghalaya","Mizoram","Nagaland","Orissa","Puducherry","Punjab","Rajasthan","Sikkim","Tamil Nadu","Tripura","Uttar Pradesh","Uttarakhand","West Bengal")

var NoState= new Array(msgs[9]);


function populateState(StateArr,selState){
	var StateList=document.getElementById("State");
	ClearList(StateList);
    if (document.getElementById("NonUSStateLbl"))
    {
        if (NoState==StateArr)
        {
        document.getElementById("NonUSStateLbl").style.display='block';
        document.getElementById("NonUSState").style.display='block';
        document.getElementById("USStateLbl").style.display='none';
        document.getElementById("USState").style.display='none';
        }
        else
        {
        document.getElementById("NonUSStateLbl").style.display='none';
        document.getElementById("NonUSState").style.display='none';
        document.getElementById("USStateLbl").style.display='block';
        document.getElementById("USState").style.display='block';  
        }      
    
    }	
	var El;
		El=new Option(msgs[8],'')
		StateList.options[StateList.options.length]=El;	
	
	for (i=0;i<StateArr.length;i++){
		El=new Option(StateArr[i],StateArr[i])
		StateList.options[StateList.options.length]=El;
	}
	StateList.value=selState

}
function ClearList(ListObj){
	var j=ListObj.options.length
	for (i=0;i<j;i++)
		ListObj.options[0]=null
}
function doCountryChange(Country,State){
if (Country!=""){
	switch (Country){
		case "USA":
			document.forms[0].State.disabled=false
			populateState(USState,State);
			break;
		case "US":
			document.forms[0].State.disabled=false
			populateState(USState,State);
			break;			
		case "Australia":
			document.forms[0].State.disabled=false
			populateState(AUState,State);
			break;	
		case "AU":
			document.forms[0].State.disabled=false
			populateState(AUState,State);
			break;				
		case "South Africa":
			document.forms[0].State.disabled=false
			populateState(SAState,State);
			break;	
		case "ZA":
			document.forms[0].State.disabled=false
			populateState(SAState,State);
			break;				
		case "Canada":
			document.forms[0].State.disabled=false
			populateState(CAState,State);
			break;	
		case "CA":
			document.forms[0].State.disabled=false
			populateState(CAState,State);
			break;				
		case "India":
			document.forms[0].State.disabled=false
			populateState(INState,State);
			break;		
		case "IN":
			document.forms[0].State.disabled=false
			populateState(INState,State);
			break;						
		default:
			document.forms[0].State.disabled=true
			populateState(NoState,'');
	
	    }
    }
    else
    {
        document.forms[0].State.disabled=true
        populateState(NoState,'');
    }
}
function loadState(country,State){
    switch (country){
        case "USA":
            document.forms[0].State.disabled=false; 
			populateState(USState,State); 
			break;
        case "Australia":
            document.forms[0].State.disabled=false; 
			populateState(AUState,State); 
			break;
        case "South Africa":
            document.forms[0].State.disabled=false; 
			populateState(SAState,State); 
			break;
        case "Canada":
            document.forms[0].State.disabled=false; 
			populateState(CAState,State); 
			break;	
        case "India":
            document.forms[0].State.disabled=false; 
			populateState(INState,State); 
			break;
        default:
            document.forms[0].State.disabled=true; 
			populateState(NoState,State);             												  
    }
}

function ValidateEmail(EmailAddress) {
if (EmailAddress.indexOf("'")>0)
	return true;
	
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     if(regex.test(EmailAddress)){
    if(EmailAddress.length == (EmailAddress.indexOf("@")+1) ) {
       return false;
       }

    if(EmailAddress.length == 0) { 
      return false; 
      }     
     }
     else
     {
		return false;
     }
     return true;
  }


       
function validateRegisterform(){
    var retval=true;
    var validatortxt=''
    var spans=document.getElementsByTagName('span')
    for (i=0;i<spans.length;i++)
    {
        if (spans[i].id.indexOf('Valid')>0)
            spans[i].style.display='none'
    }
    
    if (document.forms[0].FirstName.value==""){
        document.getElementById('FirstNameValid').style.display='block';
        validatortxt+='<li>'+msgs[0]+'</li>'
        retval=false;
    }
    if (document.forms[0].LastName.value==""){
        document.getElementById('LastNameValid').style.display='block';
        validatortxt+='<li>'+msgs[1]+'</li>'
        retval=false;
    }
    if (!document.forms[0].State.disabled)  {
	    if(document.forms[0].State.value==""){
            document.getElementById('StateValid').style.display='block';
            validatortxt+='<li>'+msgs[2]+'</li>'
            retval=false;	
	    }   
	} 
	
	if (!ValidateEmail(document.forms[0].EmailAddress.value)){
	        document.getElementById('EmailAddressValid').style.display='block';
            validatortxt+='<li>'+msgs[2]+'</li>'
            retval=false;
	
	}
    if (document.forms[0].Password.value!=""){
        if (document.forms[0].Password.value!=document.forms[0].Password1.value)
        {
            document.getElementById('Password1Valid').style.display='block';
            validatortxt+='<li>'+msgs[3]+'</li>'
            retval=false;
        }
        if (document.forms[0].Password.value.length<5)
        {
            document.getElementById('PasswordValid').style.display='block';
            validatortxt+='<li>'+msgs[4]+'</li>'
            retval=false;
        }

    }
    
    if (!retval){
        document.getElementById('SummaryValid').innerHTML='<ul>'+validatortxt+'</ul>'
        document.getElementById('SummaryValid').style.display='block';
    }




    return retval;
}  

function ValidateID(){
    var retval=true;
    var validatortxt=''
    var spans=document.getElementsByTagName('span')
    for (i=0;i<spans.length;i++)
    {
        if (spans[i].id.indexOf('Valid')>0)
            spans[i].style.display='none'
    }
    if (document.forms[0].ID.value=="")
    {
        
        validatortxt+='<li>'+msgs[6]+'</li>'
        retval=false;
    }
    else
    {
        if (document.forms[0].ID.value.length<40)
        {
            
            validatortxt+='<li>'+msgs[7]+'</li>'
            retval=false;
        }    
    }
    

    if (!retval){
        document.getElementById('SummaryValid').innerHTML='<ul>'+validatortxt+'</ul>'
        document.getElementById('SummaryValid').style.display='block';
    }
    
    return retval;

}