// JavaScript Document

//(C) www.dhtmlgoodies.com, November 2005

var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster

var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;

var dhtmlgoodies_activeId = false;

var dhtmlgoodies_slideInProgress = false;

function showHideContent(e,inputId)

{

	if(dhtmlgoodies_slideInProgress)return;

	dhtmlgoodies_slideInProgress = true;

	if(!inputId)inputId = this.id;

	inputId = inputId + '';

	var numericId = inputId.replace(/[^0-9]/g,'');

	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);



	objectIdToSlideDown = false;

	

	if(!answerDiv.style.display || answerDiv.style.display=='none'){		

		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			

			objectIdToSlideDown = numericId;

			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));

		}else{

			

			answerDiv.style.display='block';

			answerDiv.style.visibility = 'visible';

			

			slideContent(numericId,dhtmlgoodies_slideSpeed);

		}

	}else{

		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));

		dhtmlgoodies_activeId = false;

	}	

}



function slideContent(inputId,direction)

{

	

	var obj =document.getElementById('dhtmlgoodies_a' + inputId);

	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);

	height = obj.clientHeight;

	if(height==0)height = obj.offsetHeight;

	height = height + direction;

	rerunFunction = true;

	if(height>contentObj.offsetHeight){

		height = contentObj.offsetHeight;

		rerunFunction = false;

	}

	if(height<=1){

		height = 1;

		rerunFunction = false;

	}



	obj.style.height = height + 'px';

	var topPos = height - contentObj.offsetHeight;

	if(topPos>0)topPos=0;

	contentObj.style.top = topPos + 'px';

	if(rerunFunction){

		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);

	}else{

		if(height<=1){

			obj.style.display='none'; 

			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){

				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';

				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';

				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				

			}else{

				dhtmlgoodies_slideInProgress = false;

			}

		}else{

			dhtmlgoodies_activeId = inputId;

			dhtmlgoodies_slideInProgress = false;

		}

	}

}

function initShowHideDivs()

{

	var divs = document.getElementsByTagName('DIV');

	var divCounter = 1;

	for(var no=0;no<divs.length;no++){

		if(divs[no].className=='dhtmlgoodies_question'){

			divs[no].onclick = showHideContent;

			divs[no].id = 'dhtmlgoodies_q'+divCounter;

			var answer = divs[no].nextSibling;

			while(answer && answer.tagName!='DIV'){

				answer = answer.nextSibling;

			}

			answer.id = 'dhtmlgoodies_a'+divCounter;	

			contentDiv = answer.getElementsByTagName('DIV')[0];

			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	

			contentDiv.className='dhtmlgoodies_answer_content';

			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;

			answer.style.display='none';

			answer.style.height='1px';

			divCounter++;

		}		

	}	

}

window.onload = initShowHideDivs;



function MM_validateForm() { //v4.0

if (document.getElementById){

var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

for (i=0; i<(args.length-2); i+=3) {

test=args[i+2]; val=document.getElementById(args[i]);

if (val) { 

nm=val.name; 

if ((val=val.value)!="") {

if (test.indexOf('isEmail')!=-1) { 

p=val.indexOf('@');

if (p<1 || p==(val.length-1)) errors+='• '+nm+' must contain an valid e-mail address.\n';

} else if (test!='R') { 

num = parseFloat(val);

if (isNaN(val)) errors+='• '+nm+' must contain only numbers.\n';

if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

min=test.substring(8,p); max=test.substring(p+1);

if (num<min || max<num) errors+='• '+nm+' must contain a number between '+min+' and '+max+'.\n';

} } } else if (test.charAt(0) == 'R') errors += '• '+nm+' is required.\n'; }

}

//if(document.form1.Confirm_Password.value != document.form1.Password.value){ errors+='• Password not match.\n'; } 

if (errors) alert('Please correct mistakes :\n'+errors);

document.MM_returnValue = (errors == ''); } }



function crm(){ ans=confirm('Do you want really empty cart ?'); if(ans){ return true; } else { return false; } }

function delcrm(str){ ans=confirm('Do you want really delete '+str+' ?'); if(ans){ return true; } else { return false; } }



















 //payment gateway validation
function validate(){
	
	var frm = document.frmTransaction;
	var aName = Array();
	aName['account_id'] = 'Account ID';
	aName['reference_no'] = 'Reference No';
	aName['amount'] = 'Amount';
	aName['description'] = 'Description';
	aName['name'] = 'Billing Name';
	aName['address'] = 'Billing Address';
	aName['city'] = 'Billing City';
	aName['state'] = 'Billing State';
	aName['postal_code'] = 'Billing Postal Code';
	aName['country'] = 'Billing Country';
	aName['email'] = 'Billing Email';
	aName['phone'] = 'Billing Phone Number';
	aName['ship_name']='Shipping Name';
	aName['ship_address']='Shipping Address';
	aName['ship_city']='Shipping City';
	aName['ship_state']='Shipping State';
	aName['ship_postal_code']='Shipping Postal code';
	aName['ship_country']='Shipping Country';
	aName['ship_phone']='Shipping Phone';
	aName['return_url']='Return URL';
	

	for(var i = 0; i < frm.elements.length ; i++){
		if((frm.elements[i].value.length == 0)||(frm.elements[i].value=="Select Country")){
						if((frm.elements[i].name=='country')||(frm.elements[i].name=="ship_country"))
					alert("Select the " + aName[frm.elements[i].name]);
					else
					alert("Enter the " + aName[frm.elements[i].name]);
				frm.elements[i].focus();
				return false;
			}
			if(frm.elements[i].name=='account_id'){
			
			if(!validateNumeric(frm.elements[i].value)){
					alert("Account Id must be NUMERIC");
			frm.elements[i].focus();
			return false;
			}
			}
			
			if(frm.elements[i].name=='amount'){
			if(!validateNumeric(frm.elements[i].value)){
					alert("Amount should be NUMERIC");
			frm.elements[i].focus();
			return false;
			}
			}
			if((frm.elements[i].name=='postal_code')||(frm.elements[i].name == 'ship_postal_code'))
			{
			if(!validateNumeric(frm.elements[i].value)){
					alert("Postal code should be NUMERIC");
			frm.elements[i].focus();
			return false;
			}
			}	
			
			if((frm.elements[i].name=='phone')||(frm.elements[i].name =='ship_phone')){
			if(!validateNumeric(frm.elements[i].value)){
					alert("Enter a Valid CONTACT NUMBER");
			frm.elements[i].focus();
			return false;
			}
			}		
    	
    
	
		if((frm.elements[i].name == 'name')||(frm.elements[i].name == 'ship_name'))
		{
		
		if(validateNumeric(frm.elements[i].value)){
					alert("Enter your Name");
			frm.elements[i].focus();
			return false;
			}
		}
		
				
		if(frm.elements[i].name=='ship_postal_code'){
			if(!validateNumeric(frm.elements[i].value)){
					alert("Postal code should be NUMERIC");
			frm.elements[i].focus();
			return false;
			}
			}		
    
			
							
		if(frm.elements[i].name == 'email'){
				if(!validateEmail(frm.elements[i].value)){
					alert("Invalid input for " + aName[frm.elements[i].name]);
					frm.elements[i].focus();
					return false;
				}		
			}
			
	}  
	return true;
}

	function validateNumeric(numValue){
		if (!numValue.toString().match(/^[-]?\d*\.?\d*$/)) 
				return false;
		return true;		
	}

function validateEmail(email) {
    //Validating the email field
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	//"
    if (! email.match(re)) {
        return (false);
    }
    return(true);
}


Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).
        if (this[i] === value) {
            return true;
        }
    }
    return false;
};

 
