//////////////////////////////////////////////////////////////////////
// Project Name     - 	Aroxo Online Trading System.		 		//
// Company			-	Altosys Software Technologies Limited       //
// Author(s)		-	Vivek										//
// Date				-	04 April 2007								//
// Last Modified	-	11 April 2007								//
//																	//
// Description		-	Common js file for all form submit			//
//						verification.        	 					//
//																	//
//////////////////////////////////////////////////////////////////////
 
//Function to Check valid Date
var glAppAcceptText ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.,?:/!$%_()>`- \n \t \" \' ";
var glAppAcceptLine ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,?:/!$%-_ ";
var glAppAcceptNumericLine = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.,?:/!$%-_ ";
var Focuson_TXTname;

function IsAlphaNumeric(sText) {  	//Match any single non-word characters other than a-zA-Z_0-9 with space.
	reg = /([^a-zA-Z0-9 ]+)/;
//	reg = /(^[a-zA-Z ]+$)|(^[a-zA-Z0-9 ]+[\,\s][ a-zA-Z0-9]+)/;
	
	return reg.test(sText);
}
function IsAlphaNumericWithDot(sText) {  	//Match any single non-word characters other than a-zA-Z_0-9 with space.
	reg = /([^a-zA-Z0-9.\n\r ]+)/;
//	reg = /(^[a-zA-Z ]+$)|(^[a-zA-Z0-9 ]+[\,\s][ a-zA-Z0-9]+)/;
	
	return reg.test(sText);
}
function IsAlphaNumericWithDotAndMore(sText) {  	//Match any single non-word characters other than a-zA-Z_0-9 with space.
	reg = /([^a-zA-Z0-9."',.£$%&!*#@\n\r ]+)/;
//	reg = /(^[a-zA-Z ]+$)|(^[a-zA-Z0-9 ]+[\,\s][ a-zA-Z0-9]+)/;
	
	return reg.test(sText);
}
// Function to round the number to specified decimal places...
function roundNumber(number, length) {
	if (number > 8191 && number < 10485) {
		number = number-5000;
		var newnumber = Math.round(number*Math.pow(10,length))/Math.pow(10,length);
		newnumber = newnumber+5000;
	} else {
		var newnumber = Math.round(number*Math.pow(10,length))/Math.pow(10,length);
	}
	return newnumber;
}


function checkValid(data,validchars) {
	var parsed = true;
	//var validchars = "0123456789";
		
	for (var i=0; i < data.length; i++) {
		var letter = data.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
			continue;
		parsed = false;
		break;
	}
	return parsed;
}

/* Removes leading whitespaces */

function LTrim( value ) {
	
	if(value != undefined){
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
	}
	
}

/* Removes ending whitespaces */

function RTrim( value ) {
	
	if(value != undefined){
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");
	}
	
}

/* Removes leading and ending whitespaces*/

function trim( value ) {
	
	if(value != undefined){
		return LTrim(RTrim(value));
	}
	
}

/* Is decimal no. */
function isDecimal(value){
		decimal = /^-?\d+(\.\d+)?$/;
		return decimal.test(value);
}

/* Valid username for aroxo */

function validCity_County(city_countyname) {
	var parsed = true;
	var validchars = "abcdefghijklmnopqrstuvwxyz0123456789'_.- ";
	for (var i=0; i < city_countyname.length; i++) {
		var letter = city_countyname.charAt(i).toLowerCase();
	//	alert(letter+" "+validchars.indexOf(letter));
		if (validchars.indexOf(letter) != -1)
			continue;			
		parsed = false;
		break;
	}
	return parsed;
}


function validUsername(username) {
	var parsed = true;
	var validchars = "abcdefghijklmnopqrstuvwxyz0123456789_.";
	for (var i=0; i < username.length; i++) {
		var letter = username.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
			continue;
		parsed = false;
		break;
	}
	return parsed;
}

function validFirstname(firstname) {
	var parsed = true;
	var validchars = "abcdefghijklmnopqrstuvwxyz0123456789_. -";
	for (var i=0; i < firstname.length; i++) {
		var letter = firstname.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
			continue;
		parsed = false;
		break;
	}
	return parsed;
}

/* Password validation for Aroxo */

function validatePassword(password,fieldName){
	var parsed = true;
	var allowed = "abcdefghijklmnopqrstuvwxyz0123456789\")(&";

	for (var i=0; i < password.length; i++) {
		var letter = password.charAt(i).toLowerCase();
		if (allowed.indexOf(letter) != -1)
			continue;
		parsed = false;
		break;
	}
	if(!parsed){
		alert(fieldName + " Password must not contain any special characters");
		return parsed;
	}
	
	var alp = "abcdefghijklmnopqrstuvwxyz";
	var caps= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var num = "0123456789";
	var alpExist = false;
	var numExist = false;
	var capsExist = false;

	for (var i=0; i < password.length; i++) {
		var letter = password.charAt(i);
		if (caps.indexOf(letter) != -1)
			capsExist = true;

		if (alp.indexOf(letter) != -1)
			alpExist = true;
		
		if (num.indexOf(letter) != -1)
			numExist = true;
	}
	if(!(alpExist) || !(numExist) || !(capsExist)){
		alert(fieldName + " Password must contain atleast one numeric, one upper and lower case character");
		return false;
	}
	return parsed;
}

//Function to validate alphanumeric with regular EXP begins
function isAlphaNumeric(sText) {
	reg = /[\W_]/;
	return reg.test(sText);
}


// Function to disable Control key combination
function disableCtrlKey(e)
{
        //list all CTRL + key combinations you want to disable
        var forbiddenKeys = new Array('a', 'n', 'c', 'x', 'v', 'j');
        var key;
        var isCtrl;

        if(window.event)
        {
                key = window.event.keyCode;     //IE
                if(window.event.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }
        else
        {
 		key = e.which;     //firefox
                if(e.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }

        //if ctrl is pressed check if other key is in forbidenKeys array
        if(isCtrl)
        {
                for(i=0; i<forbiddenKeys.length; i++)
                {
                        //case-insensitive comparation
                        if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
                        {
                               //alert('Key combination CTRL + ' + String.fromCharCode(key)  + ' has been disabled.');
                                return false;
                        }
                }
        }
        return true;

}

/*Admin Login validation script*/
function validateLogin(){
	
	if($F('username')==""){
		alert("Whoa there. You need to enter a username to log in!");
		$('username').focus();
		return false;		
	}
	if($F('username').length < 4 ){
		alert("Username must have minimum of 4 characters");
		$('username').value ="";
		$('username').focus();
		return false;
	}
	/*if(!validUsername($F('username'))){
		alert("Username should not contain any special characters");
		$('username').value ="";
		$('username').focus();
		return false;	
	}*/
	if($F('password')==""){
		alert("Hmm. We can't see your password anywhere? Can you check it?");
		$('password').focus();
		return false;		
	}
	if($F('password').length < 6){
		alert("That password doesn't look right. It's rather short");
		$('password').value="";
		$('password').focus();
		return false;
	}	
	/*if(!validatePassword($F('password'),"")){
		$('password').value="";
		$('password').focus();
		return false;	
	}*/
	if(document.getElementById('humanVerifyCode')){
		if(trim($F('humanVerifyCode'))==""){
			alert("Please enter the code you see in the image");
			$('humanVerifyCode').focus();
			return false;		
		}
	
		if(trim($F('humanVerifyCode')).length < 5 || document.getElementById('human_error_img').title != "Verified"){
			alert("Please enter a valid verification code");
			$('humanVerifyCode').focus();
			return false;		
		}
	}
	return true;
}


/* Change admin password validataion */

function validateChangepass(){

	if($F('oldPassword')==""){
		alert("Please enter the old password");
		$('newPassword').value="";
		$('confirmPassword').value="";
		$('oldPassword').focus();
		return false;		
	}
	if($F('oldPassword').length < 8){
		alert("Password must contain atleast 8 characters");
		$('oldPassword').value="";
		$('newPassword').value="";
		$('confirmPassword').value="";
		$('oldPassword').focus();
		return false;
	}	
	/*if(!validatePassword($F('oldPassword'),"Old")){
		$('oldPassword').value="";
		$('newPassword').value="";
		$('confirmPassword').value="";
		$('oldPassword').focus();
		return false;	
	}*/
	if($F('newPassword')==""){
		alert("Please enter the new password");
		$('newPassword').focus();
		return false;		
	}
	if($F('newPassword').length < 8){
		alert("Sorry, but your new password is just too short. It should be at least 8 letters long");
		$('newPassword').value="";
		$('confirmPassword').value="";
		$('newPassword').focus();
		return false;
	}	
	/*if(!validatePassword($F('newPassword'),"New")){
		$('newPassword').value="";
		$('confirmPassword').value="";
		$('newPassword').focus();
		return false;	
	}*/
	if($F('confirmPassword') == ''){
		alert("Please enter confirm new password");
		$('confirmPassword').focus();
		return false;
	}
	if($F('newPassword')!= $F('confirmPassword')){
		alert("This is strange. It would seem that the two passwords don't match. Can you type them in again, just to be sure?");
		$('confirmPassword').value="";
		$('confirmPassword').focus();
		return false;
	}
	return true;
}

/* Change admin email validation */
function validateEditAdmin(){
	
	if(trim($F('email_id'))==""){
		alert("Please do not leave the email ID field empty");
		$('email_id').focus();
		return false;
	}
	if($F('oldEmailId') == $F('email_id')){
		alert("Old email ID and new email ID are same!")
		$('email_id').focus();
		return false;
	}
	if(!isValidEmail($F('email_id'),"")){
		alert("Please enter a valid email ID");
		$('email_id').focus();
		return false;
	}
	return true; 
}

//Function to validate emailid begins
function isValidEmail(email, required) {
	if (required==undefined) {   // if not specified, assume it's required
		required=true;
	}
	if (email==null) {
		if (required) {
			return false;
		}
		return true;
	}
	if (email.length==0) {  
		if (required) {
			return false;
		}
		return true;
	}
	if (! allValidChars(email)) {  // check to make sure all characters are valid
		return false;
	}
	if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
		return false;
	} else if (email.split("@").length-1 > 1) {  // not more than one @ 
		return false;
	} else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
		return false;
	} else if (email.indexOf("@") == email.length) {  // @ must not be the last character
		return false;
	} else if (email.indexOf("..") >=0) { // two periods in a row is not valid
		return false;
	} else if ((email.lastIndexOf(".")+1) == email.length) {  // . must not be the last character
		return false;
	} else if ((email.indexOf("@")+1) == email.lastIndexOf(".")) {  // @ must not be the last character
		return false;
	}
	return true;
}

function allValidAlph(email) {
	var parsed = true;
	var validchars = "abcdefghijklmnopqrstuvwxyz ";
	for (var i=0; i < email.length; i++) {
		var letter = email.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
			continue;
		parsed = false;
		break;
	}
	return parsed;
}
function allValidAlphAdd(email) {
	var parsed = true;
	var validchars = "abcdefghijklmnopqrstuvwxyz- ";
	for (var i=0; i < email.length; i++) {
		var letter = email.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
			continue;
		parsed = false;
		break;
	}
	return parsed;
}
function allValidChars(email) {
	var parsed = true;
	var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
	for (var i=0; i < email.length; i++) {
		var letter = email.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
			continue;
		parsed = false;
		break;
	}
	return parsed;
}
//Function to validate emailid ends
//Only numerics

function allValidNumber(email) {
	var parsed = true;
	var validchars = "0123456789.";
	for (var i=0; i < email.length; i++) {
		var letter = email.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
			continue;
		parsed = false;
		break;
	}
	return parsed;
}

// Validate Basic Registration Form
// Ramesh Murugan
// 17 April 2007
var xmlHttpChkCaptcha;
function validateBasicRegistration(){

	if($F('username')==""){
		alert("Please choose a username");
		$('username').focus();
		return false;		
	}
	if($F('username').length < 4 ){
		alert("Username must have minimum of 4 characters");
		$('username').value ="";
		$('username').focus();
		return false;
	}
	if(!validUsername($F('username'))){
		alert("Username should not contain any special characters");
		$('username').value ="";
		$('username').focus();
		return false;	
	}
	
	if($F('email_id')==""){
		alert("Please enter your email address");
		$('email_id').focus();
		return false;
	}
	if(!isValidEmail($F('email_id'),"")){
		alert("Please enter a valid email address");
		//$('email_id').value = "";
		$('email_id').focus();
		return false;
	}
	if($F('password')==""){
		alert("Please enter the password");
		$('password').value="";
		$('confirmPassword').value="";
		$('password').focus();
		return false;		
	}
	if($F('password').length < 6){
		alert("Password must contain at least 6 characters");
		$('password').value="";
		$('confirmPassword').value="";
		$('password').focus();
		return false;
	}	
	/*if(!validatePassword($F('password'),"")){
		$('password').value="";
		$('confirmPassword').value="";
		$('password').focus();
		return false;	
	}*/
	if($F('password')!= $F('confirmPassword')){
		alert("Your passwords don't match. Please check them");
		$('confirmPassword').value="";
		$('confirmPassword').focus();
		return false;
	}
	/*if(trim($F('securityQuestion'))==""){
		alert("Please enter the security question");
		$('securityQuestion').focus();
		return false;		
	}
	if(trim($F('securityAnswer'))==""){
		alert("Please enter the security answer");
		$('securityAnswer').focus();
		return false;		
	}*/
	if(trim($F('firstname'))==""){
		alert("Please enter your first name");
		$('firstname').focus();
		return false;		
	}
	if(!isAppAcceptLine(trim($F('firstname')))){
		alert("Invalid firstname");
		//$('firstname').value ="";
		$('firstname').focus();
		return false;	
	} 
	
	if(trim($F('surname'))==""){
		alert("Please enter your surname");
		$('surname').focus();
		return false;		
	}
	
	
	if(trim($F('city'))==""){
		alert("Please enter your city");
		$('city').focus();
		return false;		
	}
	if(!isAppAcceptLine(trim($F('city')))){
		alert("Invalid city name");
		$('city').focus();
		return false;		
	} 
	if(trim($F('country')) == 0 ){
		alert("Please select your country");
		$('country').focus();
		return false;		
	}
	if(trim($F('humanVerifyCode'))==""){
		alert("Please enter the code you see in the image");
		$('humanVerifyCode').focus();
		return false;		
	}

	if(trim($F('humanVerifyCode')).length < 5 || document.getElementById('imgCaptcha').title != "Verified"){
		alert("Please enter a valid verification code");
		$('humanVerifyCode').focus();
		return false;		
	}
	
	if(!document.frmBasicRegistration.acceptTerms.checked){
	
		alert("You must accept Aroxo's user terms and conditions before you can continue");
		//$('acceptTerms').focus();
		return false;
	}
	return true;
}

function validateCaptcha(){
	if($F('humanVerifyCode').length >= 5){
		xmlHttpChkCaptcha =GetXmlHttpObject();
		if (xmlHttpChkCaptcha==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		<!--attribgrpid="+atrid+"&srchval="+str-->
		var url="validateCaptcha.php?captcha=" + $F('humanVerifyCode')
		xmlHttpChkCaptcha.onreadystatechange=checkCaptcha;
		xmlHttpChkCaptcha.open("GET",url,true);
		xmlHttpChkCaptcha.send(null);	
	}
}

function checkCaptcha(){
	if (xmlHttpChkCaptcha.readyState==4){ 
		var result 	= xmlHttpChkCaptcha.responseText;	
	
		if(result){
	
			if(document.getElementById("human_error_msg")){
				document.getElementById("human_error_msg").innerHTML="";;
			}
			$('human_error_img').src 	= 'images/available.png';

			$('human_error_img').alt 	= 'Verified';
			$('human_error_img').title 	= 'Verified';
			return false
		}
		else{
			if(document.getElementById("human_error_msg")){
				document.getElementById("human_error_msg").innerHTML="Invalid Human verification code";;
			}
			$('human_error_img').src 	= 'images/unavailable.png';
			$('human_error_img').alt 	= 'Invalid verification code';
			$('human_error_img').title 	= 'Invalid verification code';
			return true;
		}
	}		
}

// Validate Basic Data
// Ramesh Murugan
// 17 April 2007
function validateBasicData(){
	if($F('email_id')==""){
		alert("Please enter the email address");
		$('email_id').focus();
		return false;
	}
	if(!isValidEmail($F('email_id'),"")){
		alert("Please enter a valid email address");
		//$('email_id').value = "";
		$('email_id').focus();
		return false;
	}
	if($F('confirm_email_id')==""){
		alert("Please enter the confirm email address");
		$('confirm_email_id').focus();
		return false;
	}
	if($F('email_id') != $F('confirm_email_id')){
		alert("Mismatch of confirm email address");
		$('confirm_email_id').focus();
		return false;
	}
	
	if(trim($F('firstname'))==""){
		alert("Please enter your first name");
		$('firstname').focus();
		return false;		
	}
	if(!allValidAlph(trim($F('firstname')))){
		alert("Invalid firstname");
		//$('firstname').value ="";
		$('firstname').focus();
		return false;	
	}
	if(trim($F('surname'))!="" && !allValidAlph($F('surname'))){
		alert("Invalid surname");
		//$('firstname').value ="";
		$('surname').focus();
		return false;	
	}
	if(trim($F('city'))==""){
		alert("Please enter the city");
		$('city').focus();
		return false;		
	}
	if(!allValidAlph($F('city'))){
		alert("Invalid city name");
		$('city').focus();
		return false;		
	}
	if(trim($F('country')) == 0 ){
		alert("Please select the country");
		$('country').focus();
		return false;		
	}
	return true;
}

// Validate Addess Form
// Ramesh Murugan
// 17 April 2007
function validateAddress(){
	$("errorMsg").innerHTML = '';
	if(trim($F('address1'))=="" && trim($F('address2'))=="" && trim($F('address3'))==""){
		alert("Please enter the address");
		$('address1').focus();
		return false;		
	}
	if(trim($F('city'))==""){
		alert("Please enter the city");
		$('city').focus();
		return false;		
	}
	if(!allValidAlph($F('city'))){
		alert("Invalid city name");
		$('city').focus();
		return false;		
	}
	if(trim($F('zip_code'))==""){
		alert("Please enter the postal code");
		$('zip_code').focus();
		return false;		
	}
	if(IsAlphaNumeric($F('zip_code'))){
		alert("Invalid postal code");
		$('zip_code').focus();
		return false;		
	}
	if(trim($F('country')) == 0 ){
		alert("Please select the country");
		$('country').focus();
		return false;		
	}
	if(trim($F('deliveryCountry')) == 0 ){
		alert("Please select the delivery country");
		$('deliveryCountry').focus();
		return false;		
	}
	if(trim($F('deliveryCity'))!="" && !allValidAlph($F('deliveryCity'))){
		alert("Invalid delivery city name");
		$('deliveryCity').focus();
		return false;		
	}
	/*if(trim($F('deliveryZipcode'))!="" && isAlphaNumeric($F('deliveryZipcode'))){
		alert("Invalid delivery postal code");
		$('deliveryZipcode').focus();
		return false;		
	}*/
	return true;
}

// Validate seller info
// Ramesh Murugan
// 24 April 2007
function validateSellerInfo(){
	if(trim($F('vat_number'))!="" && IsAlphaNumeric($F('vat_number'))){
		alert("Invalid vat number");
		$('vat_number').focus();
		return false;	
	}
	if(trim($F('sales_country')) == 0 ){
		alert("Please select the primary sales country");
		$('sales_country').focus();
		return false;		
	}
	return true;
}
// CHeck for valid vat number
function isValidVatNo(e){  
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /^[a-zA-z0-9]/;
	if(reg.test(keychar) && key != 94 && key != 95)
		return true;
	else if(key == 8 || key ==0 || key ==32 || key == 13 || key == 45)
		return true;
	else
		return false;
} 


// Validate User's Contact Preference
// Ramesh Murugan
// 17 April 2007
function validateContactPref(dd,mm,yyyy,frm_date){

	/*alert(document.frmBasicData.gender[0].checked);
	alert(document.frmBasicData.gender[1].selected);
	alert(document.frmBasicData.gender.value);
	alert($F("gender"));
	alert($F("gender").value);
	return false;*/
	
	//$("signupCode").value=document.getElementById("signupCode_tmp").value
	

	
	if($F("surname") == ""){
		alert("Please enter the surname");
		$('surname').focus();
		return false;
	}
	//The below if condition has been blocked by Karthikeyan R on 17-July
	//====================================================================
/*	if(!document.frmBasicData.gender[0].checked && !document.frmBasicData.gender[1].checked){
		alert("Ooops, you've missed out your sex");
		document.frmBasicData.gender[0].focus();
		return false;
	}
*/	

/*	if((document.getElementById(dd).value!='')&&(document.getElementById(mm).value!='')&&(document.getElementById(yyyy).value!='')){
	document.getElementById(frm_date).value = document.getElementById(dd).value+"/"+document.getElementById(mm).value+"/"+document.getElementById(yyyy).value;
	}
	else{
		document.getElementById(frm_date).value="00/00/0000";
	}*/
	
	if(document.getElementById(dd).value !="" || document.getElementById(mm).value !="" || document.getElementById(yyyy).value !=""){
		document.getElementById(frm_date).value = document.getElementById(dd).value+"/"+document.getElementById(mm).value+"/"+document.getElementById(yyyy).value;
		
		
		if(document.getElementById(dd).value =="" && document.getElementById(mm).value =="" && document.getElementById(yyyy).value==""){
		document.getElementById(frm_date).value="00"+"/"+"00"+"/"+"0000";
	
		}
		if(!isValidDOB(document.getElementById(frm_date),document.getElementById(dd)))
		{
			document.getElementById(frm_date).value ='';
			return false;
		}
	}
	else{
		document.getElementById(frm_date).value ='';
	}
	
	if(document.getElementById("mobile_validate").value=="true")
	{
	
		mobile_check = /^[+0]+[\d\- \d]{8,}$/;	
		//mobile_check = /^[+0]{1}\d{2,4}\s|-{1}\d|\s|-{6,9}$/;              // xxxxxxxxxx
		if( $F("mobile_number") == ""){
			alert("Please enter your mobile number");
			$('mobile_number').focus();
			return false;
		}
		m = $F("mobile_number");
		if($F("mobile_number") != "" && !mobile_check.test(m)){
			alert("Please enter your mobile number");
			$('mobile_number').focus();
			return false;
		}
	}		
	return true;
}
function changeMobileTR(tag)
{

	if(tag.value==1)
	{
		document.getElementById("mobile_number_div1").style.display="block";
		document.getElementById("mobile_number_div2").style.display="block";
		document.getElementById("mobile_number_td1").className="tdbox_l_green";
		document.getElementById("mobile_number_td2").className="tdbox_l";
		document.getElementById("mobile_validate").value="true";
		
	}
	else
	{
		document.getElementById("mobile_number_div1").style.display="none";
		document.getElementById("mobile_number_div2").style.display="none";	
		document.getElementById("mobile_number_td1").className="";
		document.getElementById("mobile_number_td2").className="";
		document.getElementById("mobile_validate").value="false";
	}
}

// Validate Edit User's Personal Info Form
// Ramesh Murugan
// 17 April 2007
function validateEditPersonalInfo(dd,mm,yyyy,frm_date){

	if(trim($F('firstname'))==""){
		alert("Errr. You've not included a first name!");
		$('firstname').focus();
		return false;		
	}
	if(!allValidAlph(trim($F('firstname')))){
		alert("Invalid firstname");
		//$('firstname').value ="";
		$('firstname').focus();
		return false;	
	}
	if(trim($F('surname'))!="" && !allValidAlph($F('surname'))){
		alert("Invalid surname");
		//$('firstname').value ="";
		$('surname').focus();
		return false;	
	}
	document.getElementById(frm_date).value = document.getElementById(dd).value+"/"+document.getElementById(mm).value+"/"+document.getElementById(yyyy).value;
	if(document.getElementById(dd).value =="" && document.getElementById(mm).value =="" && document.getElementById(yyyy).value==""){
	document.getElementById(frm_date).value="00"+"/"+"00"+"/"+"0000";
	
	}else if(!isValidDBDateInEdit(document.getElementById(frm_date),document.getElementById(dd)))
	{
		return false;
	}
/*	if(trim($F('deliveryAddress1'))=="" && trim($F('deliveryAddress2'))=="" && trim($F('deliveryAddress3'))==""){
		alert("Please enter the delivery address");
		$('deliveryAddress1').focus();
		return false;		
	} */
	if(trim($F('city'))==""){
		alert("Ooops. Can you just quickly add in where you are?");
		$('city').focus();
		return false;		
	}
	if(!allValidAlphAdd($F('city'))){
		alert("Invalid city name");
		$('city').focus();
		return false;		
	}
/*	if(trim($F('deliveryZipcode'))==""){
		alert("Please enter the postal code");
		$('deliveryZipcode').focus();
		return false;		
	} */
	if(IsAlphaNumeric($F('zip_code'))){
		alert("Invalid postal code");
		$('zip_code').focus();
		return false;		
	}
	if(trim($F('country')) == 0 ){
		alert("Please select the country");
		$('country').focus();
		return false;		
	}
	if(trim($F('deliveryCity'))==""){
		alert("Please enter the delivery city");
		$('deliveryCity').focus();
		return false;		
	}
	if(!allValidAlphAdd($F('deliveryCity'))){
		alert("Invalid delivery city name");
		$('deliveryCity').focus();
		return false;		
	}
	if(trim($F('deliveryCountry')) == 0 ){
		alert("Please select the delivery country");
		$('deliveryCountry').focus();
		return false;		
	}
	if(trim($F('deliveryCity'))!="" && !allValidAlphAdd($F('deliveryCity'))){
		alert("Invalid delivery city name");
		$('deliveryCity').focus();
		return false;		
	}
	
	/* if(trim($F('deliveryZipcode'))!="" && isAlphaNumeric($F('deliveryZipcode'))){
		alert("Invalid delivery postal code");
		$('deliveryZipcode').focus();
		return false;		
	}*/
	return true;
}
function focusUsername(){
	if($F('username')!=""){
		if($F('username').length < 4 ){
			//alert("Username must have minimum of 4 characters");
			//$('username').value ="";
			$('username').focus();
			return false;
		}
		if(!validUsername($F('username'))){
			//alert("Username must not contain any special characters");
			//$('username').value ="";
			$('username').focus();
			return false;	
		}
	}
	else{
		$('username').focus();
		return false;
	}
		return true;
	
}



/*var xmlHttpChkAvail;
function validateCheckAvailability(frm){
	//	document.getElementById("errorMsg").innerHTML = '';
	// if(document.getElementById("errorMsg"))
	//	$("errorMsg").innerHTML = '';
	if($F('username')!=""){
		if($F('username').length < 4 ){
			alert("Username must have minimum of 4 characters");
			//$('username').value ="";
			$('username').focus();
			return false;
		}
		if(!validUsername($F('username'))){
			alert("Username must not contain any special characters");
			//$('username').value ="";
			$('username').focus();
			return false;	
		}
		//$('option').value = "checkAvailability";
		//frm.submit();
		//return true;
		//document.getElementById('frmBasicRegistration').submit();
		xmlHttpChkAvail=GetXmlHttpObject();
		if (xmlHttpChkAvail==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		<!--attribgrpid="+atrid+"&srchval="+str-->
		var url="checkusernameavailability.php?uname=" + $F('username')
		xmlHttpChkAvail.onreadystatechange=showAvailability;
		xmlHttpChkAvail.open("GET",url,true);
		xmlHttpChkAvail.send(null);	
	}
}
function showAvailability(){
	if (xmlHttpChkAvail.readyState==4){ 
		var result 	= xmlHttpChkAvail.responseText;	
		if(result){
			$('imgAvail').src 	= 'images/available.png';
			$('imgAvail').alt 	= 'Username available';
			$('imgAvail').title = 'Username available';
			if($('username_error_div') != undefined)
			$('username_error_div').innerHTML = '';
			$('username_error_td_id').style.border = '2px solid #ffffff';
			
		}
		else{
			$('imgAvail').src = 'images/unavailable.png';
			$('imgAvail').alt 	= 'Username unavailable';
			$('imgAvail').title = 'Username unavailable';
			if($('username_error_div') != undefined){
				$('username_error_div').innerHTML = '<font class="rederrortxt"> Username already exists</font>';
				$('username_error_td_id').style.border = '1px solid #FF0000';
			}

		}
	}
}*/


// changes done by mujifur 07/01/09

function isMailId(email){
 var filter=/^.+@.+\..{2,3}$/

 if (filter.test(email))
    testresults=true
 else {
    testresults=false
}
 return testresults
}

// changes done by mujifur 07/01/09
function validateUserName(varEmptyCheck,varAlreadyExistCheck){

	varErrorFlag=true;
	
	if(trim($F('username'))==""){
		if(varEmptyCheck){
			
			markAsError('username','Please enter a username');
			varErrorFlag=false;
		}
	}
	else if($F('username').length < 4 ){
		markAsError('username','Username must have minimum of 4 characters!');
		varErrorFlag=false;
	}
	
	else if(!validUsername($F('username')) ){
		markAsError('username','Username must not contain any special characters!');
		varErrorFlag=false;
	}	
	else if(!checkWord_exist($F('username'),'aroxo')){
		markAsError('username',"Sorry, you can't use our name in your username");
		varErrorFlag=false;
	}	
	else{
		if(varAlreadyExistCheck){
			validateCheckAvailability();
		}
	}

	return varErrorFlag;
	

}

function checkWord_exist(fieldname,chkword)
{
	var chkname=fieldname.toLowerCase();
	var findat=chkname.indexOf(chkword,0);
	if(findat<0) return true;
	else return false;
	
}

// changes done by mujifur 07/01/09
function validateEmailAddress(varEmptyCheck){
	
	varErrorFlag=true;
	
	if(trim($F('email_id'))==""){
		if(varEmptyCheck){
			markAsError('email_id','Please enter your email address');
			varErrorFlag=false;
		}
	}
	else if(!isMailId($F('email_id'))){
		
		markAsError('email_id','Invalid email address');
		varErrorFlag=false;
	}
	else{
		markAsValid('email_id');	
		
	}
	return varErrorFlag;
/*	else if (true) {
		
	}
	else if(true){
		markAsError('email_id','Email address already exits!');	
	}*/
	
}
// changes done by mujifur 07/01/09
function validateConfirmEmail(varEmptyCheck){
	
	varErrorFlag=true;
	
	if(trim($F('confirmemail'))==""){
		if(varEmptyCheck){
			markAsError('confirmemail','Please confirm your email address');
			varErrorFlag=false;		
		}
	}
	else if(!isMailId($F('confirmemail'))){
		
		markAsError('confirmemail','Invalid email address');
		varErrorFlag=false;
	}
	else if($F('confirmemail')!= $F('email_id'))
	{
		markAsError('confirmemail','Your email addresses do not match');
		varErrorFlag=false;		
		
	}
	else{
		markAsValid('confirmemail');	
	}
	return varErrorFlag;
/*	else if (true) {
		
	}
	else if(true){
		markAsError('email_id','Email address already exits!');	
	}*/
	
}
// changes done by mujifur 07/01/09
function validatePassword(varEmptyCheck){
	
	varErrorFlag=true;
	
	if(trim($F('password'))==""){
		if(varEmptyCheck){
			markAsError('password','Please enter a password');
				varErrorFlag=false;		
		}
	}
	
	else if($F('password').length < 6){
		markAsError('password','Password must contain at least 6 characters');
		varErrorFlag=false;	
		
	}
	else{
		markAsValid('password');	
	}
	return varErrorFlag;
}
// changes done by mujifur 07/01/09
function validateConfirmPassword(varEmptyCheck){
	
	varErrorFlag=true;
	
	if(trim($F('confirmPassword'))==""){
		if(varEmptyCheck){
			markAsError('confirmPassword','Please confirm your password');
			varErrorFlag=false;		
		}
	}
	else if( $F('confirmPassword')!= $F('password') ){
		markAsError('confirmPassword','Ooops - your password does not match');
		varErrorFlag=false;	
	}
	else{
		markAsValid('confirmPassword');	
	}
	return varErrorFlag;
	
}
// changes done by mujifur 07/01/09
function validateFirstName(varEmptyCheck){

	varErrorFlag=true;

	if(trim($F('firstname'))==""){
		if(varEmptyCheck){
			markAsError('firstname','Please enter your first name');
			varErrorFlag=false;		
		}
	}

	else if( !validFirstname($F('firstname'))  ||   !isAppAcceptNumericLine($F('firstname')) )
	{
		markAsError('firstname','Firstname should not contain any special characters');
		varErrorFlag=false;		
		
	}
	else{
		var firstname_value=$F('firstname');
		firstname_value = firstname_value.substr(0, 1).toUpperCase() + firstname_value.substr(1);
		document.getElementById("firstname").value=firstname_value;
		markAsValid('firstname');	
	}
	return varErrorFlag;

	
}
// changes done by mujifur 07/01/09
/*function validateFirstName(varEmptyCheck){
	
	varErrorFlag=true;

	if(trim($F('firstname'))==""){
		if(varEmptyCheck){
			markAsError('firstname','Firstname should not be empty!');
			varErrorFlag=false;		
		}
	}

	else if( !isAppAcceptLine($F('firstname')) )
	{
		markAsError('firstname','Firstname must not contain any special characters! ');
		varErrorFlag=false;		
		
	}
	else{
		var firstname_value=$F('firstname');
		firstname_value = firstname_value.substr(0, 1).toUpperCase() + firstname_value.substr(1);
		document.getElementById("firstname").value=firstname_value;
		markAsValid('firstname');	
	}
	return varErrorFlag;
	
} */
// changes done by mujifur 07/01/09
function validateSurname(varEmptyCheck){
	
	varErrorFlag=true;
	
	if(trim($F('surname'))==""){
		if(varEmptyCheck){
			markAsError('surname','Please enter your surname');
			varErrorFlag=false;		
		}
	}

	else if( !validFirstname($F('surname'))  ||   !isAppAcceptNumericLine($F('surname')) )
	{
		markAsError('surname','Surname should not contain any special characters ');
		varErrorFlag=false;		
	}
	else{
		var firstname_value=$F('surname');
		firstname_value = firstname_value.substr(0, 1).toUpperCase() + firstname_value.substr(1);
		document.getElementById("surname").value=firstname_value;
		markAsValid('surname');	
	}
	return varErrorFlag;
	
}
// changes done by mujifur 07/01/09
function validateCity(varEmptyCheck){
	
	varErrorFlag=true;

	if(trim($F('city'))==""){
		if(varEmptyCheck){
			markAsError('city','Please enter a city/county name');
			varErrorFlag=false;		
		}
	}

	else if( !validCity_County($F('city')))
	{
		markAsError('city','City/County should not contain any special characters!');
		varErrorFlag=false;	
		
	}
	else{
		var firstname_value=$F('city');
		firstname_value = firstname_value.substr(0, 1).toUpperCase() + firstname_value.substr(1);
		document.getElementById("city").value=firstname_value;
		markAsValid('city');	
	}
	return varErrorFlag;

	
}
// changes done by mujifur 07/01/09
function validateHuman(varEmptyCheck){
	
	varErrorFlag=true;
	
	if(trim($F('humanVerifyCode'))==""){
		if(varEmptyCheck){
			markAsError('human','Please type the code you see into the box');
			varErrorFlag=false;
		}
	}
	else{
		//markAsValid('human');	
	}
	
	return varErrorFlag;
	
	
}
// changes done by mujifur 07/01/09
function validateHumanLength(){
	
	varErrorFlag=true;
	
	if ( ( $F('humanVerifyCode').length <5) && ($F('humanVerifyCode').length>0) ) {
		
			markAsError('human','Sorry - the code does not match :(');
			varErrorFlag=false;
		
	}
	
	return varErrorFlag;
	
	
}

// changes done by mujifur 07/01/09
function validateAcceptTerms(varEmptyCheck){
	
	varErrorFlag=true;
	if(document.getElementById("acceptTerms").checked==false){
		markAsError('accept','Please confirm you accept our terms and conditions');
		varErrorFlag=false;
	}
	else{
		markAsValid('accept');	
	}
	
	return varErrorFlag;
	
	
}



// changes done by mujifur 07/01/09
var xmlHttpChkAvail;
function validateCheckAvailability(){
	
		xmlHttpChkAvail=GetXmlHttpObject();
		if (xmlHttpChkAvail==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url="checkusernameavailability.php?uname=" + $F('username')
		xmlHttpChkAvail.onreadystatechange=showAvailability;
		xmlHttpChkAvail.open("GET",url,true);
		xmlHttpChkAvail.send(null);
	
}

// changes done by mujifur 07/01/09
function showAvailability(){
	if (xmlHttpChkAvail.readyState==4){ 
		var result 	= xmlHttpChkAvail.responseText;	
		
		if(result){
			markAsValid('username');
			
		}
		else{
			markAsError('username','Sorry - some early bird has already taken that username :(');	
		}
	}
}


// changes done by mujifur 07/01/09
function markAsError(tag,errorMsg){

	right_td_tag = tag + "_right_td";
	left_td_tag  = tag + "_left_td";
	error_msg    = tag + "_error_msg";
	error_img    = tag + "_error_img"
	

	//$(right_td_tag).className = 'tdbox_l_error';
	//$(left_td_tag).className = 'tdbox_l_error';
	
	
	$(error_img).src = 'images/unavailable.png';
	//$(error_img).alt 	= 'Username unavailable';
	//$(error_img).title = 'Username unavailable';
	
	$(error_msg).innerHTML = errorMsg;
	
	
}
// changes done by mujifur 07/01/09
function markAsValid(tag){
	

	right_td_tag = tag + "_right_td";
	left_td_tag  = tag + "_left_td";
	error_msg    = tag + "_error_msg";
	error_img   = tag + "_error_img";

	$(right_td_tag).className = 'tdbox_l';
	$(left_td_tag).className = 'tdbox_l_green';
	$(error_img).src 	= 'images/available.png';
	//$(error_img).alt 	= 'Username available';
	//$(error_img).title = 'Username available';
	
	
	$(error_msg).innerHTML ="";
	
}
// changes done by mujifur 07/01/09
function validateUserReg(form_tag){
	varRegErrorFlag=true;
	if(! validateUserName(true,false) ){
		varRegErrorFlag=false;
		document.getElementById('username').focus();
	}
	if(! validateEmailAddress(true) ){
		if(varRegErrorFlag){
			varRegErrorFlag=false;
			document.getElementById('email_id').focus();
		}	
	}
	if(! validateConfirmEmail(true) ){
		if(varRegErrorFlag){
			varRegErrorFlag=false;
			document.getElementById('confirmemail').focus();
		}	
	}
	if(! validatePassword(true) ){
		if(varRegErrorFlag){
			varRegErrorFlag=false;
			document.getElementById('password').focus();
		}	
	}	
	if(! validateConfirmPassword(true) ){
		if(varRegErrorFlag){
			varRegErrorFlag=false;
			document.getElementById('confirmPassword').focus();
		}	
	}
	if(! validateFirstName(true) ){
		if(varRegErrorFlag){
			varRegErrorFlag=false;
			document.getElementById('firstname').focus();
		}	
	}
	/*if(! validateSurname(true) ){
		if(varRegErrorFlag){
			varRegErrorFlag=false;
			document.getElementById('surname').focus();
		}	
	}*/
	if(! validateCity(true) ){
		if(varRegErrorFlag){
			varRegErrorFlag=false;
			document.getElementById('city').focus();
		}	
	}

	if(! validateHuman(true) ){
	
		if(varRegErrorFlag){
			varRegErrorFlag=false;
			document.getElementById('humanVerifyCode').focus();
		}	
	}

	if(! validateAcceptTerms(true) ){
	
		if(varRegErrorFlag){
			varRegErrorFlag=false;
			//document.getElementById('acceptTerms').focus();
		}	
	}

	username_error_msg_str=trim(document.getElementById("username_error_msg").innerHTML);
	human_error_mst_str=trim(document.getElementById("human_error_msg").innerHTML);
	
	if(username_error_msg_str!=""){
			varRegErrorFlag=false;
	}
	if(human_error_mst_str!=""){
			varRegErrorFlag=false;
	}
	

	return varRegErrorFlag;
	
}


function comparePasswords(){
	if($F('confirmPassword') != ''){
		if($F('password')==""){
			alert("Please enter the password");
			$('password').value="";
			$('confirmPassword').value="";
			$('password').focus();
			return false;		
		}
		if($F('password').length < 6){
			alert("Password must contain at least 6 characters");
			$('password').value="";
			$('confirmPassword').value="";
			$('password').focus();
			return false;
		}	
		if($F('password')!= $F('confirmPassword')){
			//$('confirmPassword').value="";
			$('confirmPassword').focus();
			$('imgPsss').src 	= 'images/unavailable.png';
			$('imgPsss').alt 	= 'Password mismatch';
			$('imgPsss').title 	= 'Password mismatch';
	
			return false;
		}
		else{
				$('imgPsss').src 	= 'images/available.png';
				$('imgPsss').alt 	= 'Passwords mathced';
				$('imgPsss').title 	= 'Passwords mathced';
		}
	}
}

function confirmemailnull(){
	if($F('confirmemail') == ''){
		$('confirmemail').focus();
		return false;
	}
	return true;
}

function compareemails(){
	if($F('confirmemail') != ''){
		if($F('email_id')==""){
			alert("Please enter the email address");
			$('email_id').value="";
			$('confirmemail').value="";
			$('email_id').focus();
			return false;		
		}
		
		if($F('email_id')!= $F('confirmemail')){
		//	$('confirmemail').value="";
			$('confirmemail').focus();
			$('imgemail').src 	= 'images/unavailable.png';
			$('imgemail').alt 	= 'Email address mismatch';
			$('imgemail').title = 'Email address mismatch';
	
			return false;
		}
		else{
				$('imgemail').src 	= 'images/available.png';
				$('imgemail').alt 	= 'Email address mathced';
				$('imgemail').title = 'Email address mathced';
		}
	}
}


// Registration contact preference
function showMsg(fld, flg){
	
	if(flg)
		document.getElementById(fld).style.visibility = 'visible';	
	else
		document.getElementById(fld).style.visibility = 'hidden';	
}

function validateEditEmail(){
	if(trim($F('email_id'))==""){
		alert("Errr. You've not entered your new email address");
		$('email_id').focus();
		return false;
	}
	if($F('oldEmailId') == $F('email_id')){
		alert("Old email ID and new email ID are same!")
		$('email_id').focus();
		return false;
	}
	if(!isValidEmail($F('email_id'),"")){
		alert("Please enter a valid new email ID");
		$('email_id').focus();
		return false;
	}
	if($F('confirmEmailId')== ''){
		alert("Oh. You've not re-entered your email address")
		$('confirmEmailId').focus();
		return false;
	}
	if($F('confirmEmailId') != $F('email_id')){
		alert("Ooops, your email address doesn't match!")
		$('confirmEmailId').focus();
		return false;
	}
	if($F('password')==""){
		alert("Whoa there. You've not entered a password! We can't have just anybody change your email address, can we?");
		$('password').value="";
		$('password').focus();
		return false;		
	}
	/*if(!validatePassword($F('password'),"")){
		$('password').value="";
		$('password').focus();
		return false;	
	}*/
	if($F('password').length < 8){
		alert("We don't think your password is right");
		$('password').value="";
		$('password').focus();
		return false;
	}
	return true; 
}

// Copy address information to delivery address fields
// Ramesh Murugan
// 17 April 2007
function validateForgotPass(){
	if($F('usermail')==""){
		alert("Please enter the username / email ID");
		$('usermail').focus();
		return false;		
	}
	if(!validUsername($F('usermail')) && !isValidEmail($F('usermail'),"")){
		alert("Please enter a valid username / email ID");
		$('usermail').focus();
		return false;
	}
	return true;
}

// Copy address information to delivery address fields
// Ramesh Murugan
// 17 April 2007
function sameAddress(){
	if($("sameDeliveryAddress").checked){
		$("deliveryAddress1").value 	= $("address1").value;
		$("deliveryAddress2").value 	= $("address2").value;
		$("deliveryAddress3").value 	= $("address3").value;
		$("deliveryCity").value 		= $("city").value;
		$("deliveryZipcode").value 	= $("zip_code").value;
		$("deliveryCountry").value 	= $("country").value;
	}
	else{
		$("deliveryAddress1").value	= "";
		$("deliveryAddress2").value	= "";
		$("deliveryAddress3").value 	= "";
		$("deliveryCity").value 	  	= "";
		$("deliveryZipcode").value 	= "";
		$("deliveryCountry").value 	= 0;

	}
}

// Synchronise two Fileds
// Ramesh Murugan
// 17 April 2007
function syncFileds(source, target, condition){
	if(condition){
		$(target).value = source.name;	
	}
	var txtId = target.substring(9,10);
	//alert(id); // && elements[i].alt == id
	with(document.frmOffer){
		for(i=0;i<elements.length;i++){
			var alt = elements[i].alt;
			if(elements[i].type == "text" && txtId == alt)
			{		
				elements[i].value = source.options[source.selectedIndex].title;
			}
		}	
	}

}

// validate close account form
// Ramesh Murugan
// 09 May 2007
function validateCloseAc(){
	if($F('password')==""){
		alert("Please enter the password");
		$('password').focus();
		return false;		
	}
	if($F('password').length < 8){
		alert("Password must contain atleast 8 characters");
		$('password').value="";
		$('password').focus();
		return false;
	}		
	return confirm('Are you sure want to close your account?');
}

// validate Contact aroxo
// Ramesh Murugan
// 10 May 2007
function validateContactAroxo(maxlength){
/*	if(trim($F('email_id'))==""){
		alert("Please do not leave the Email ID field empty");
		$('email_id').focus();
		return false;
	}
	if(!isValidEmail($F('email_id'),"")){
		alert("Please enter a valid Email ID");
		$('email_id').focus();
		return false;
	}
	if($F('username')==""){
		alert("Please enter the username");
		$('username').focus();
		return false;		
	}
	if($F('username').length < 6 ){
		alert("Username must have minimum of 6 characters");
		$('username').focus();
		return false;
	}
	if(!validUsername($F('username'))){
		alert("Username must not contain any special characters");
		$('username').focus();
		return false;	
	}*/
	if(trim($F('humanVerifyCode'))==""){
		alert("Please enter the code you see in the image ");
		$('humanVerifyCode').focus();
		return false;		
	}
	if(trim($F('message'))== ''){
		alert("Please enter some message")
		$('message').focus();
		return false;
	}
	if($F('message').length > maxlength){
		alert("Please enter less than or equal to " + maxlength + " Characters");
		$('message').focus();
		return false;
	}
}

// Fix maximum length
function fixLength(e, fldname, dispfld, maxlength){
	
	var key = window.event ? e.keyCode : e.which;	
		

	if($F(fldname).length > (maxlength-1) && (key != 8 && key !=0 && key !=46 && key != 16 && key != 17 && key !=18 && key !=37 && key != 38 && key !=39 && key != 40 && key!= 116)){
		alert("Maximum length is "+ maxlength +" Characters")
		
		$(fldname).value=$(fldname).value.substring(0,maxlength-1);		
		$(fldname).focus();
		
		if($F(fldname).length>maxlength)
		{
		$(fldname).value=$(fldname).value.substring(0,maxlength-1);				
		$(dispfld).innerHTML = $F(fldname).length+1;	
		}
		return false;
	}
	else{
		//alert($F(fldname).length);
		$(dispfld).innerHTML = $F(fldname).length+1;	
		if($F(fldname).length>maxlength)
		{
		$(fldname).value=$(fldname).value.substring(0,maxlength-1);				
		$(dispfld).innerHTML = $F(fldname).length+1;	
		}
		
		return true;
	}
	
}

// Fix maximum length
function maxLength_TextArea(e, fldname, maxlength){

	var key = window.event ? e.keyCode : e.which;	
		
//	alert(key);
	if($F(fldname).length > maxlength - 1 && (key != 8 && key !=0 && key !=46 && key != 16 && key != 17 && key !=18 && key !=37 && key != 38 && key !=39 && key != 40 && key!= 116)){
		alert("Sorry, your notes are too long")
		$(fldname).focus();
		return false;
	}
	else{
		return true;
	}
}

function lockField(e){
	var key = window.event ? e.keyCode : e.which;
	if(key == 0){
		return true;
	}
	else{
		return false;
	}
}

// Validate Sales payment Terms & Condition form(Add).

function postageform(details,price)
{
var postageDet = document.getElementById(details);
var postagePrice = document.getElementById(price);

	if((postageDet.value=="")||(postageDet.value=="e.g. First Class"))
		{
			alert("Please enter name.");
			postageDet.focus();
			return false;
		}
	if(!isNaN(postageDet.value))
		{
			alert("Name should not be number.");
			postageDet.focus();
			return false;
		}
	if(postagePrice.value != '')
		{
			if(!checkValid(postagePrice.value,'1234567890.')) { 
				alert("Price should be number.");
				postagePrice.focus();
				return false;
				}
		}
		else
		{
			alert("Please enter price.");
			postagePrice.focus();
			return false;
		}
	return true;
}
// Validate Sales payment Terms & Condition form(Edit).
function postageformedit(details,price)
{
	var postageDet = document.getElementById(details);
	var postagePrice = document.getElementById(price);
	
	if(postageDet.value=="")
		{
			alert("Please enter name.");
			postageDet.focus();
			return false;
		}
	if(!isNaN(postageDet.value))
		{
			alert("Name should not be number.");
			postageDet.focus();
			return false;
		}

	if(postagePrice.value != '')
		{
			if(!checkValid(postagePrice.value,'1234567890.,')) { 
				alert("Price should be number.");
				postagePrice.focus();
				return false;
				}
		}
		else
		{
			alert("Please enter price.");
			postagePrice.focus();
			return false;
		}
	return true;
}
// Validate Sales payment Terms & Condition form(Template Add).
function templateform(fieldname)
{
var Invalidchars = " ";
		
var templateName = document.getElementById(fieldname);
	if(templateName.value != '')
		{
			if(!checkValid(templateName.value,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 .,?:/!$%-_\'')) { 
				alert("Template name should not contain any special characters.");
				templateName.focus();
				return false;
				}
		}
		else
		{
			alert("Please enter template name.");
			templateName.focus();
			return false;
		}
		
	with(document.salespay){
		for(i=0;i<elements.length;i++){
			if((elements[i].type=='text') &&(elements[i].name.substr(0,18)=="gateWayDescription")&&(trim(elements[i].value)=="")&& (elements[i].disabled==false)){
				alert("Please enter payment instruction.");
				document.getElementById(elements[i].id).focus();
				return false;
				
			}
			
			if((elements[i].type=='text') &&(elements[i].name.substr(0,18)=="gateWayDescription")&& (elements[i].disabled==false)){
				var tempText = trim(elements[i].value);
				/* if(tempText.indexOf(" ")!=-1){
					//alert("Please enter payment instruction without any space.");
					alert('We think there\'s something wrong with the payment gateway information you\'ve provided us with. Make sure that there are no spaces in it. If you get this wrong - you won\'t get paid');
					document.getElementById(elements[i].id).focus();
					return false;
				}*/
				
			}
			  
		}
	}	
		
	var status=checkPaymentOptions();
	return status;
	
}

function isValidVatNo(e,submitbuttonname){  
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /^[a-zA-z0-9]/;
	if(key == 13){
	document.getElementById(submitbuttonname).focus();
	return true;
	}
}

function rightClick(e) {
	if (navigator.appName == 'Netscape' && e.which == 3) {
		return false;
	}
	if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
		return false;
	}
}

//Disable right click script 
//visit http://www.rainbow.arch.scriptmania.com/scripts/ 
/*var message="Sorry, right-click has been disabled"; 
/////////////////////////////////// 
function clickIE() {if (document.all) {(message);return false;}} 
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) { 
if (e.which==2||e.which==3) {(message);return false;}}} 
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} 
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} 
document.oncontextmenu= new Function("return false");*/

function showHelp(det){
	if(det=='show') {
	document.getElementById('help').style.visibility = "visible";
	document.getElementById('help').style.display = "inline";
	} else {
	document.getElementById('help').style.visibility = "hidden";	
	document.getElementById('help').style.display = "none";
	}
}

function showHelpPrice(det){
	if(det=='show') {
	document.getElementById('helpPrice').style.visibility = "visible";
	document.getElementById('helpPrice').style.display = "inline";
	} else {
	document.getElementById('helpPrice').style.visibility = "hidden";	
	document.getElementById('helpPrice').style.display = "none";
	}
}

function showHelpDetails(det,id){
	if(det=='show') {
	document.getElementById(id).style.visibility = "visible";
	document.getElementById(id).style.display = "inline";
	} else {
	document.getElementById(id).style.visibility = "hidden";	
	document.getElementById(id).style.display = "none";
	}
}

// --> 


	var xmlHttp

	var attribId;
	function showHint(atrid,str)
	{
	if (str.length==0)
	  { 
	  document.getElementById("data_"+atrid).innerHTML="";
	  document.getElementById("data_"+atrid).style.display = 'none';
	  return;
	  }
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	attribId = atrid;

	var url="searchtext.php?attribgrpid="+atrid+"&srchval="+str;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	} 

	function stateChanged() 
	{ 
		if (xmlHttp.readyState==4)
		{ 
		var result = xmlHttp.responseText;
		represult = result.replace('"','');
			if(represult != ''){
				document.getElementById("data_"+attribId).style.display = 'list-item';
				document.getElementById("data_"+attribId).innerHTML=xmlHttp.responseText;
			}else{
				document.getElementById("data_"+attribId).style.display = 'none';				
			}
		}
	}
	
	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 putdata(field,data){
		document.getElementById('txt_'+field).value = data;
		document.getElementById("data_"+field).innerHTML = '';
		document.getElementById("data_"+field).style.display = 'none';
	}
	
 // Ajax Condtion for Wanted Ad, Stock Creation, Test Template.	
 function showNext(argParent,argCount,argChild,argAttrCnt,argAttrgrpId,argAllSpecAttrGrpId, argActionType){
	 if(document.getElementById('imageDiv')){
		if(argParent == 'Optional' && argParent != 'Others'){
	 		loadImage(argAttrgrpId,'Optional');
		}else if(argParent != 'Others'){
	 		loadImage(argParent);
		}
	 }
	for(col=0;col<argAttrCnt;col++){
		if(document.getElementById('td_'+col)){
			document.getElementById('td_'+col).style.background = '#FFFFFF';
		}
	}
	if(argParent!='' && argParent!='Others' && argParent!='Optional'){
		if(document.getElementById('txtDiv_'+argCount)){
			document.getElementById('txtDiv_'+argCount).style.display = 'none';
		}
		argCount++;
		if(argCount<argAttrCnt){
			for(i=argCount;i<argAttrCnt;i++){ // To hide all remaining div tags.
				if(document.getElementById('txt_'+argAttrgrpId)){
					document.getElementById('txt_'+argAttrgrpId).value='';
				}
				if(document.getElementById('txtDiv_'+i)){
					divCode = document.getElementById('txtDiv_'+i).innerHTML;
					stringsplit = divCode.split(' ');
					stringsplit = stringsplit[1].split("_");
					if(document.getElementById('txt_'+stringsplit[1])){
						//document.getElementById('txt_'+stringsplit[1]).value = '';
						document.getElementById('hidd_'+stringsplit[1]).value = '';
					}
				document.getElementById('txtDiv_'+i).style.display = "none";
				}
				if(document.getElementById('div_'+i)){
					document.getElementById('div_'+i).innerHTML = '-';	
				}
				if(document.getElementById('div1_'+i)){
					document.getElementById('div1_'+i).style.display = 'none';
				}
				if(document.getElementById('hidd_'+argAttrgrpId)){
					document.getElementById('hidd_'+argAttrgrpId).value='';
				}
			}
		}else{
			i=argAttrCnt-1;
			if(document.getElementById('txtDiv_'+i)){
				//document.getElementById('txtDiv_'+i).style.visibility = "hidden";
				document.getElementById('txtDiv_'+i).style.display = "none";
			}
			if(document.getElementById('txt_'+argAttrgrpId)){
				document.getElementById('txt_'+argAttrgrpId).value='';
			}
			if(document.getElementById('hidd_'+argAttrgrpId)){
				document.getElementById('hidd_'+argAttrgrpId).value='';
			}
		}
		//alert('Type:-'+argActionType);
		var catArr = new Array();
		new Ajax.Request('loadattribute.php', {
		method:'post',
		parameters: {parent: argParent,fieldCount: argCount,child: argChild,attribGrp: argAttrgrpId, argActionType: argActionType},
		onSuccess: function(assignedCategories){
			myCatDesc = assignedCategories.responseText || "No Data";
			if(myCatDesc == 'False'){ //alert("Value not assigned, Please select others");
			document.getElementById('div_'+argCount).innerHTML = "-<input type='hidden' value='valueNA' name='hiddenTool' id='hiddenTool'>";
			return false;
			}else{
			if(document.getElementById('div_'+argCount)){
				//alert(myCatDesc);
			document.getElementById('div_'+argCount).innerHTML = myCatDesc;
			}
			}
			if(document.getElementById('div1_'+argCount)){
			document.getElementById('div1_'+argCount).style.display = 'inline';
			}
			argC = argCount -1;
			if(document.getElementById('txtDiv_'+argC))	// To hide the text box
				//document.getElementById('txtDiv_'+argC).style.visibility = "hidden";
				document.getElementById('txtDiv_'+argC).style.display = "none";
		},
		onFailure: function(){ alert('Something went wrong...') }
		});	
		}else if(argParent=='Others'){ // Make the text box visible
			document.getElementById('txtDiv_'+argCount).style.visibility = "visible";
			document.getElementById('txtDiv_'+argCount).style.display = "inline";
			//document.getElementById('txt_'+argAttrgrpId).value = '';
			document.getElementById('txt_'+argAttrgrpId).focus();
			argCount++;
			for(i=argCount;i<=argAttrCnt;i++){
				if(document.getElementById('div_'+i)){
					document.getElementById('div_'+i).innerHTML = '-';	
					if(document.getElementById('txtDiv_'+i)){
						document.getElementById('txtDiv_'+i).style.visibility = "hidden";
						//document.getElementById('txtDiv_'+i).style.display = "none";
					}
				}
				if(document.getElementById('div1_'+i)){
					document.getElementById('div1_'+i).style.display = 'none';
				}	
			}
			if(argAllSpecAttrGrpId){ 
				specAttribIds = argAllSpecAttrGrpId.split(',');
				if(specAttribIds.length != 0){
					attrblength = specAttribIds.length;
					for(n=argCount;n<attrblength;n++){
						if(specAttribIds[n] != 0 ){
							document.getElementById('hidd_'+specAttribIds[n]).value = 'Others';
							//document.getElementById('txt_'+specAttribIds[n]).value ='';
							document.getElementById('txtDiv_'+argCount).style.visibility = "visible";
							document.getElementById('div_'+n).innerHTML ='';
							document.getElementById('txtDiv_'+argCount).style.display = "inline";
							argCount++;
						}
					}
				}
				//showNext('Optional',argCount-1,argChild,argAttrCnt,specAttribIds[attrblength-2]);
			//}else{	
				//showNext('Optional',argCount-1,argChild,argAttrCnt,argAttrgrpId);			
			}
		
	} 
	else if(argParent=='Optional' || argChild=='Optional'){ // This to list all values with respective group, If it is an 	optional. 
		if(document.getElementById('txtDiv_'+argCount)){
				document.getElementById('txtDiv_'+argCount).style.display = "none";		
		}
		argCount++;
		for(i=argCount;i<=argAttrCnt;i++){
			if(document.getElementById('div_'+i)){
				document.getElementById('div_'+i).innerHTML = '-';	
				if(document.getElementById('txtDiv_'+i)){
					//document.getElementById('txtDiv_'+i).style.visibility = "hidden";	
					document.getElementById('txtDiv_'+i).style.display = "none";
				}				
			}
		}	
		var valueList = new Array();
			new Ajax.Request('loadattribute.php', {
			method:'post',
			parameters: {groupId: argAttrgrpId,fieldCount: argCount,child: argChild, argActionType: argActionType},
			onSuccess: function(optionalFunction){
				valueList = optionalFunction.responseText || "No Data";
				if(valueList == 'False'){
					document.getElementById('div_'+argCount).innerHTML = "-<input type='hidden' value='valueNA' name='hiddenTool' id='hiddenTool'>";
					return false;
				}else{
					if(document.getElementById('div_'+argCount)){
						document.getElementById('div_'+argCount).innerHTML = valueList;
					}
				}
				argC = argCount -1;
				//alert('txtDiv_'+argC);
				//if(document.getElementById('txtDiv_'+argC))	// To hide the text box
					//document.getElementById('txtDiv_'+argC).style.visibility = "hidden";		
			},
			onFailure: function(){ alert('Something went wrong...') }
			});			
	}
}

// Ajax Condtion for Wanted Ad, Stock Creation, Test Template.	
 function showAlertNext(argParent,argCount,argChild,argAttrCnt,argAttrgrpId,argAllSpecAttrGrpId){
	 if(document.getElementById('imageDiv')){
		if(argParent == 'Optional' && argParent != 'Others'){
	 		loadImage(argAttrgrpId,'Optional');
		}else if(argParent != 'Others'){
	 		loadImage(argParent);		
		}
	 }
	for(col=0;col<argAttrCnt;col++){
		if(document.getElementById('td_'+col)){
			document.getElementById('td_'+col).style.background = '#FFFFFF';
		}
	}
	if(argParent!='' && argParent!='Others' && argParent!='Optional'){
		if(document.getElementById('txtDiv_'+argCount)){
			document.getElementById('txtDiv_'+argCount).style.display = 'none';
		}
		argCount++;
		if(argCount<argAttrCnt){
			for(i=argCount;i<argAttrCnt;i++){ // To hide all remaining div tags.
				if(document.getElementById('txt_'+argAttrgrpId)){
					document.getElementById('txt_'+argAttrgrpId).value='';
				}
				if(document.getElementById('txtDiv_'+i)){
					divCode = document.getElementById('txtDiv_'+i).innerHTML;
					stringsplit = divCode.split(' ');
					stringsplit = stringsplit[1].split("_");
					if(document.getElementById('txt_'+stringsplit[1])){
						//document.getElementById('txt_'+stringsplit[1]).value = '';
						document.getElementById('hidd_'+stringsplit[1]).value = '';
					}
				document.getElementById('txtDiv_'+i).style.display = "none";
				}
				if(document.getElementById('div_'+i)){
					document.getElementById('div_'+i).innerHTML = '-';	
				}
				if(document.getElementById('div1_'+i)){
					document.getElementById('div1_'+i).style.display = 'none';
				}
				if(document.getElementById('hidd_'+argAttrgrpId)){
					document.getElementById('hidd_'+argAttrgrpId).value='';
				}
			}
		}else{
			i=argAttrCnt-1;
			if(document.getElementById('txtDiv_'+i)){
				//document.getElementById('txtDiv_'+i).style.visibility = "hidden";
				document.getElementById('txtDiv_'+i).style.display = "none";
			}
			if(document.getElementById('txt_'+argAttrgrpId)){
				document.getElementById('txt_'+argAttrgrpId).value='';
			}
			if(document.getElementById('hidd_'+argAttrgrpId)){
				document.getElementById('hidd_'+argAttrgrpId).value='';
			}
		}
		var catArr = new Array();
		new Ajax.Request('alertloadattribute.php', {
		method:'post',
		parameters: {parent: argParent,fieldCount: argCount,child: argChild,attribGrp: argAttrgrpId},
		onSuccess: function(assignedCategories){
			myCatDesc = assignedCategories.responseText || "No Data";
			if(myCatDesc == 'False'){ //alert("Value not assigned, Please select others");
			document.getElementById('div_'+argCount).innerHTML = "-<input type='hidden' value='valueNA' name='hiddenTool' id='hiddenTool'>";
			return false;
			}else{
			if(document.getElementById('div_'+argCount)){
				//alert(myCatDesc);
			document.getElementById('div_'+argCount).innerHTML = myCatDesc;
			}
			}
			if(document.getElementById('div1_'+argCount)){
			document.getElementById('div1_'+argCount).style.display = 'inline';
			}
			argC = argCount -1;
			if(document.getElementById('txtDiv_'+argC))	// To hide the text box
				//document.getElementById('txtDiv_'+argC).style.visibility = "hidden";
				document.getElementById('txtDiv_'+argC).style.display = "none";
		},
		onFailure: function(){ alert('Something went wrong...') }
		});	
		}else if(argParent=='Others'){ // Make the text box visible
			document.getElementById('txtDiv_'+argCount).style.visibility = "visible";
			document.getElementById('txtDiv_'+argCount).style.display = "inline";
			//document.getElementById('txt_'+argAttrgrpId).value = '';
			document.getElementById('txt_'+argAttrgrpId).focus();
			argCount++;
			for(i=argCount;i<=argAttrCnt;i++){
				if(document.getElementById('div_'+i)){
					document.getElementById('div_'+i).innerHTML = '-';	
					if(document.getElementById('txtDiv_'+i)){
						document.getElementById('txtDiv_'+i).style.visibility = "hidden";
						//document.getElementById('txtDiv_'+i).style.display = "none";
					}
				}
				if(document.getElementById('div1_'+i)){
					document.getElementById('div1_'+i).style.display = 'none';
				}	
			}
			if(argAllSpecAttrGrpId){ 
				specAttribIds = argAllSpecAttrGrpId.split(',');
				if(specAttribIds.length != 0){
					attrblength = specAttribIds.length;
					for(n=argCount;n<attrblength;n++){
						if(specAttribIds[n] != 0 ){
							document.getElementById('hidd_'+specAttribIds[n]).value = 'Others';
							//document.getElementById('txt_'+specAttribIds[n]).value ='';
							document.getElementById('txtDiv_'+argCount).style.visibility = "visible";
							document.getElementById('div_'+n).innerHTML ='';
							document.getElementById('txtDiv_'+argCount).style.display = "inline";
							argCount++;
						}
					}
				}
				//showNext('Optional',argCount-1,argChild,argAttrCnt,specAttribIds[attrblength-2]);
			//}else{	
				//showNext('Optional',argCount-1,argChild,argAttrCnt,argAttrgrpId);			
			}
		
	} 
	else if(argParent=='Optional' || argChild=='Optional'){ // This to list all values with respective group, If it is an 	optional. 
		if(document.getElementById('txtDiv_'+argCount)){
				document.getElementById('txtDiv_'+argCount).style.display = "none";		
		}
		argCount++;
		for(i=argCount;i<=argAttrCnt;i++){
			if(document.getElementById('div_'+i)){
				document.getElementById('div_'+i).innerHTML = '-';	
				if(document.getElementById('txtDiv_'+i)){
					//document.getElementById('txtDiv_'+i).style.visibility = "hidden";	
					document.getElementById('txtDiv_'+i).style.display = "none";
				}				
			}
		}	
		var valueList = new Array();
			new Ajax.Request('alertloadattribute.php', {
			method:'post',
			parameters: {groupId: argAttrgrpId,fieldCount: argCount,child: argChild},
			onSuccess: function(optionalFunction){
				valueList = optionalFunction.responseText || "No Data";
				document.getElementById('div_'+argCount).innerHTML = valueList;
				argC = argCount -1;
				//alert('txtDiv_'+argC);
				//if(document.getElementById('txtDiv_'+argC))	// To hide the text box
					//document.getElementById('txtDiv_'+argC).style.visibility = "hidden";		
			},
			onFailure: function(){ alert('Something went wrong...') }
			});			
	}
}


function loadImage(argParent,isOptional){
	var valueList = new Array();
	new Ajax.Request('imageload.php', {
	method:'post',
	parameters: {assignId: argParent,isopt:isOptional},
	onSuccess: function(optionalFunction){
		valueList = optionalFunction.responseText || "Images not available";
		document.getElementById('imageDiv').innerHTML = valueList;
	},
	onFailure: function(){ alert('Something went wrong...') }
	});			
}

function imageSelector(argAssignId,argAttrGrpId,allAttrib,argText){
	arrAllAttr = allAttrib.split(',');
	divId = arrAllAttr.indexOf(argAttrGrpId);
	var allCntElim = document.template.elements.length;
	if(document.getElementById(argAttrGrpId)){
		if(document.getElementById(argAttrGrpId).type == 'radio'){
			for(k=0;k<allCntElim;k++){ 
				if(document.template.elements[k].type == 'radio'){
					if(document.template.elements[k].value == argAssignId){
						document.template.elements[k].checked = true;
						showNext(argAssignId,divId,'','',argAttrGrpId);
					}
				}
			}
		}
	}
	if(document.getElementById(argAttrGrpId)){
		if(document.getElementById(argAttrGrpId).type == 'select-one'){
			document.getElementById(argAttrGrpId).value = argAssignId;
			document.getElementById(argAttrGrpId).focus();
			showNext(argAssignId,divId,'','',argAttrGrpId);
			return true;
		}
	}
	if(document.getElementById(argAttrGrpId)){
		if(document.getElementById(argAttrGrpId).type == 'text'){
			document.getElementById(argAttrGrpId).value = argText;
			showNext(argAssignId,divId,'','',argAttrGrpId);
			return true;
		}
	}	
	if(document.getElementById(argAttrGrpId)){
		if(document.getElementById(argAttrGrpId).type == 'textarea'){
			document.getElementById(argAttrGrpId).value = argText;
			showNext(argAssignId,divId,'','',argAttrGrpId);
			return true;
		}
	}
	if(document.getElementById(argAttrGrpId+ "[]")){
		if(document.getElementById(argAttrGrpId+ "[]").type == 'checkbox'){
			for(k=0;k<allCntElim;k++){ 
				if(document.template.elements[k].type == 'checkbox'){
					if(document.template.elements[k].value == argAssignId){
						document.template.elements[k].checked = true;
						showNext(argAssignId,divId,'','',argAttrGrpId);
						return true;
					}
				}
			}
		}
	}	
}

function checkb(curObj, curObjVal){
	var chks = document.getElementsByName(curObj.name);
	var hasChecked = 0;
	for (var i = 0; i < chks.length; i++){
		if (chks[i].value == curObjVal){
			chks[i].checked = true;
		}else{
			chks[i].checked = false;
		}
	}
}

// Template form validation(Generic)

function htmlFieldValidate(allIds){
	var arr = new Array(allIds);
	arrSplit = allIds.split(',');
	var allAttrib = arrSplit.length;
	var allCntElim = document.template.elements.length;
	for(i=0;i<allAttrib;i++){
			// Validate Check Box
			if(document.getElementById(arrSplit[i]+ "[]")){
				//alert(document.getElementById(arrSplit[i]+ "[]").type);
				if(document.getElementById(arrSplit[i]+ "[]").type == 'checkbox'){
				checkchk = 0;
				curCheck = 0;
				for(k=0;k<allCntElim;k++){
					currname = document.template.elements[k].name;
					currname = currname.replace('[','');
					currname = currname.replace(']','');							  
					if(currname == arrSplit[i] && document.template.elements[k].type == 'checkbox'){
							if(curCheck == 0) curCheck = k;
						if(document.template.elements[k].checked == true){
							checkchk++;
							if(document.template.elements[k].value == 'Others'){
								if(document.getElementById('txt_'+arrSplit[i]).value!=''){
									if(!checkValid(document.getElementById('txt_'+arrSplit[i]).value,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 ')) { 
										alert("Please enter only alphanumeric characters.");
										document.getElementById('td_'+i).style.background = '#FAD3E2';
										document.getElementById('txt_'+arrSplit[i]).focus();
										return false;
										}
								}
								else
								{							
										alert("please enter text.");
										document.getElementById('td_'+i).style.background = '#FAD3E2';
										document.getElementById('txt_'+arrSplit[i]).focus();
										return false;	
								}
							}
						}
					}
				}
				if(checkchk<1){
					alert("please check the item.");
					document.getElementById('td_'+i).style.background = '#FAD3E2';
					document.template.elements[curCheck].focus();
					return false;
				}
			}
		}			
			// Validate Radio Button.
		if(document.getElementById(arrSplit[i])){
			if(document.getElementById(arrSplit[i]).type == 'radio'){
			radiochk = 0;
			curRadio = 0;
				for(j=0;j<allCntElim;j++){
					if(document.template.elements[j].name == arrSplit[i] && document.template.elements[j].type == 'radio'){
							if(curRadio == 0)curRadio = j;
						if(document.template.elements[j].checked == true){
							radiochk++;
							if(document.template.elements[j].value == 'Others'){
								if(document.getElementById('txt_'+arrSplit[i]).value!=''){
									if(!checkValid(document.getElementById('txt_'+arrSplit[i]).value,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 ')) { 
										alert("Please enter only alphanumeric characters.");
										document.getElementById('td_'+i).style.background = '#FAD3E2';
										document.getElementById('txt_'+arrSplit[i]).focus();
										return false;
										}
								}
								else
								{							
										alert("please enter text.");
										document.getElementById('txt_'+arrSplit[i]).focus();
					    				document.getElementById('td_'+i).style.background = '#FAD3E2';
										return false;	
								}
							}
						}
					}
				}
				if(radiochk<1){
					alert("please check the item.");
					document.getElementById('td_'+i).style.background = '#FAD3E2';
					document.template.elements[curRadio].focus();
					return false;
				}
			}
		}
		if(document.getElementById(arrSplit[i])){
			if(document.getElementById(arrSplit[i]).type == 'select-one'){
				if(document.getElementById(arrSplit[i]).value != ''){
					if(document.getElementById(arrSplit[i]).value == 'Others'){
						if(document.getElementById('txt_'+arrSplit[i]).value != ''){
							if(!checkValid(document.getElementById('txt_'+arrSplit[i]).value,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 ')) { 
								alert("Please enter only alphanumeric characters.");
								document.getElementById('td_'+i).style.background = '#FAD3E2';
								document.getElementById('txt_'+arrSplit[i]).focus();
								return false;
								}
						}
						else
						{
							alert("Please enter text");
							document.getElementById('td_'+i).style.background = '#FAD3E2';
							document.getElementById('txt_'+arrSplit[i]).focus();
							return false;
						}
					}
				}
				else
				{
					alert("Please select item.");
					document.getElementById('td_'+i).style.background = '#FAD3E2';
					document.getElementById(arrSplit[i]).focus();
					return false;								
				}
			}
		}
		if(document.getElementById(arrSplit[i])){
			if(document.getElementById(arrSplit[i]).type == 'text'){
				if(document.getElementById(arrSplit[i]).value != ''){
					if(!checkValid(document.getElementById(arrSplit[i]).value,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890/ ')) { 
						alert("Please enter only alphanumeric characters.");
					    document.getElementById('td_'+i).style.background = '#FAD3E2';
						document.getElementById(arrSplit[i]).focus();
						return false;
						}
				}
				else
				{
					alert("Please enter text.");
					document.getElementById('td_'+i).style.background = '#FAD3E2';
					document.getElementById(arrSplit[i]).focus();
					return false;	
				}
			}
		}
		if(document.getElementById(arrSplit[i])){
			if(document.getElementById(arrSplit[i]).type == 'textarea'){
				if(document.getElementById(arrSplit[i]).value == ''){
					alert("Please enter text.");
					document.getElementById(arrSplit[i]).focus();
					document.getElementById('td_'+i).style.background = '#FAD3E2';
					return false;
				}
			}
		}
		if(document.getElementById('hidd_'+arrSplit[i])){
			if(document.getElementById('hidd_'+arrSplit[i]).type == 'hidden'){
				if(document.getElementById('hidd_'+arrSplit[i]).value == 'Others'){
					if(document.getElementById('txt_'+arrSplit[i]).value == ''){						
							alert("Please enter text.");
							document.getElementById('txt_'+arrSplit[i]).focus();
							document.getElementById('td_'+i).style.background = '#FAD3E2';
							return false;
					}
					if(!checkValid(document.getElementById('txt_'+arrSplit[i]).value,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890/ ')) { 
							alert("Please enter only alphanumeric characters.");
							document.getElementById('txt_'+arrSplit[i]).focus();
							document.getElementById('td_'+i).style.background = '#FAD3E2';
							return false;
					}					
				}
			}
		}
		if(document.getElementById('hiddenTool')){
			if(document.getElementById('hiddenTool').value == 'valueNA'){
						alert("Product is not availabe for last selection, please select others.");
						return false;
			}
				
		}
	}
}

function validateFormStock(){
	var flag_notes;
	var msprice = document.frmStock.minimum_sell_price;
	var cond = document.frmStock.condition;
	var stkavailable = document.frmStock.stock_available;
	var itemname = document.frmStock.item_name;
	var isunlimited = document.frmStock.is_unlimited;
	var note     =document.frmStock.note;
	var diff     =document.getElementById('difference');
	/*flag_notes=limitText(note);
	if(flag_notes==false){
		return false;
	}*/
	if (trim($F("note")) == "Include here any difference from Aroxo's product description, and anything else you want to say about your item."){
		$("note").value='';
	}
	
	if(!checkValid(note,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.,?:/!$%()> \n \t `\"\'-   ')){
			alert("Special charecters & numbers not allowed.");
			return false;	
	}
	if(trim(msprice.value)!=''){
		if(!checkValid(msprice.value,'1234567890.')){
			alert("Price should be numbers");
			msprice.focus();
			return false;
		}
	}
	/* else{
		alert("Please enter Price");
		msprice.focus();
		return false;		
	} */
   // commented by mujifur 05/02/09 . Stock price may be empty

	if(cond.value == 0){
		alert("You need to tell us what condition the item is");
		cond.focus();
		return false;
	}
	
	if((stkavailable.value=='')&&(isunlimited.checked==false)){
		alert("You need to tell us how many you have available. We then make sure that you cannot sell more than this number");
		stkavailable.focus();
		return false;
	}
	if(isunlimited.checked==false){
		if(!checkValid(stkavailable.value,'1234567890')){
			alert("Stock available on Aroxo should be numbers");
			stkavailable.focus();
			return false;			
		}
	}
	
	//The below validation for ajax file upload
	
	if(document.imageform.item_image.value != "" && document.getElementById('is_img_uploaded').value == ""){
		alert("You've not uploaded your image. If you want to add it to the stock item, click \"UPLOAD\".");
		return false;
	}

    if(diff.checked==false){
		alert('You need to confirm that your item matches our description before you can create this stock item. Please note any differences in the other notes field');
		return false;
	}
	/*if(itemname.value!=''){
		if(!checkValid(itemname.value,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789- ')){
			alert("Item Name can be alphanumeric with hypen and spaces ");
			itemname.focus();
			return false;
		}
	}
	else{
		alert("Please enter Item Name");
		itemname.focus();
		return false;
	}*/
	//The line is added by Karthikeyan R- on 30-Oct-07 for ajax file upload
	document.frmStock.submit();
	//return true;
	
}

function checkUnlimited(){
	var isunlimited = document.frmStock.is_unlimited;
	var stkavailable = document.frmStock.stock_available;
	
	if(isunlimited.checked==true){
		stkavailable.value='';
		showMsg('unlimted_stock',1);
	}
	else{
		showMsg('unlimted_stock',0);
	}
}

function checkStkAvailable(){
	var isunlimited = document.frmStock.is_unlimited;
	var stkavailable = document.frmStock.stock_available;
	
	if(stkavailable.value!=''){
	   isunlimited.checked=false;
	}
}

function validateWantedForm(){
	
	var price = document.frmStock.price;
	var cond = document.frmStock.condition;
	var quantity = document.frmStock.quantity;
	var expiredate = document.frmStock.expire_date;

	if(trim(price.value)!=''){
		if(!checkValid(price.value,'1234567890.')){
			alert("Price should be numbers");
			price.focus();
			return false;
		}
		if(trim(price.value)=='0'){
		alert("Price should not be Zero");
		price.focus();
		return false;		
		}
		if(trim(price.value)<='0.01'){
		alert("Price should be greater than or equal to 0.01");
		price.focus();
		return false;		
		}
	}
	else{
		alert("Errr, you've not set a price!");
		price.focus();
		return false;		
	}
	
	
	if(trim(quantity.value)!=''){
		if(!checkValid(quantity.value,'1234567890')){
			alert("Quantity should be numbers");
			quantity.focus();
			return false;
		}
	}
			
	if(trim(quantity.value)==0){
		alert("Quantity should not Zero.");
		quantity.focus();
		return false;		
	}else if(trim(quantity.value)==''){
		alert("Please enter Quantity");
		quantity.focus();
		return false;			
	}
	
	if(cond.value == 0){
		alert("You've missed out the item condition - just select it above");
		cond.focus();
		return false;
	}

	if (trim($F("note")) == "Sellers see these notes before they send you offers, so if you've got any special requirements stick them here."){
			$("note").value='';
	}
	

	/*if(!limitText(document.getElementById("note"))){
		return false;
	}*/

		
	//The line is added by Karthikeyan R- on 30-Oct-07 for ajax file upload
	 document.frmStock.submit();
	//return true;
}


//The below function is copied from validateWantedForm for UAT2.0 - done by Karthikeyan R on 22-July-08 
function validateWantedForm_Amend(){
	
	var price = document.frmStock.price;
	var cond = document.frmStock.condition;
	var quantity = document.frmStock.quantity;
	var expiredate = document.frmStock.expire_date;
	
	if(trim(price.value)!=''){
		if(!checkValid(price.value,'1234567890.')){
			alert("Price should be numbers");
			price.focus();
			return false;
		}
		if(trim(price.value)=='0'){
		alert("Price should not be Zero");
		price.focus();
		return false;		
		}
		if(trim(price.value)<='0.01'){
		alert("Price should be greater than or equal to 0.01");
		price.focus();
		return false;		
		}
	}
	else{
		alert("Ooop, there's no price! You'll not get very far without a price");
		price.focus();
		return false;		
	}
	
		
	if(trim(quantity.value)!=''){
		if(!checkValid(quantity.value,'1234567890')){
			alert("Quantity should be numbers");
			quantity.focus();
			return false;
		}
	}
	if(trim(quantity.value)==0){
		alert("Quantity should not Zero.");
		quantity.focus();
		return false;		
	}else if(trim(quantity.value)==''){
		alert("Please enter Quantity");
		quantity.focus();
		return false;			
	}
	
	if(cond.value == 0){
		alert("You've missed out the item condition - just select it above");
		cond.focus();
		return false;
	}
	
/*	if (trim($F("note")) == "Sellers see these notes before they send you offers, so if you&rsquo;ve got any special requirements stick them here."){
			$("note").value='';
	}
*/
	/*if(expiredate.value == 0){
		alert("Please Select Ad expires in");
		expiredate.focus();
		return false;
	} */
	//The line is added by Karthikeyan R- on 30-Oct-07 for ajax file upload
	 document.frmStock.submit();
	//return true;
}

// Offer Management
// Contact Fee Calculation
// Ramesh Murugan
var varSpnId=0;
function contactFee(source, argId, argTemplateId, e){
		varSpnId	= argId;
		quantity 	= document.getElementById("quantity_" + varSpnId).value;
		price		= document.getElementById("price_" + varSpnId).value;
		if(price.substring(price.length-1,price.length) == '.') return true;
		if(source.title == "offerprice" && trim(quantity) == ''){
			if(trim(price) != '' && !isDecimal(price))
				alert("Please enter valid price");
			return false;
		}

		if(trim(quantity) != ''){
			if(isNaN(quantity)){
				alert("Please enter valid quantity");
				return false;
			}
			if(price == '' ){ //!checkValid(price.value,'1234567890.')
				alert("Please enter your price for the current offer");
				return false;
			}
			else if(!isDecimal(price)){
				alert("Please enter valid price");
				return false;
			}
			
		
		
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null){
			  alert ("Your browser does not support AJAX!");
			  return;
			} 
			var url="contactfee.php?template_id=" + argTemplateId + "&quantity=" + quantity + "&price=" + price;
			xmlHttp.onreadystatechange=setContactFee;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			//alert(document.getElementsByTag('span'));
		}	
}

// Offer Management
// Contact Fee Calculation for Quick Fill.
// Dharma Raj R.

function contactFeeQuickFill(source, argTemplateId){
		quantity 	= document.getElementById("quantityQF").value;
		price		= document.getElementById("priceQF").value;
		xmlHttp=GetXmlHttpObject()
		
		if(trim(price) != ''){
			if(price.substring(price.length-1,price.length) == '.') return true;
				if(trim(price) != '' && !isDecimal(price)){
					alert("Please enter valid price");
					source.value = '';
					document.getElementById("priceQF").value = '';
					return false;
			}
		}

		if(trim(quantity) != ''){
			if(isNaN(quantity)){
				alert("Please enter valid quantity");
				return false;
			}
			if(price == '' ){ //!checkValid(price.value,'1234567890.')
				alert("Please enter your price for the current offer");
				return false;
			}
			else if(!isDecimal(price)){
				alert("Please enter valid price");
				return false;
			}
		}

		if (xmlHttp==null){
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		var url="contactfee.php?template_id=" + argTemplateId + "&quantity=" + quantity + "&price=" + price;
		xmlHttp.onreadystatechange=setContactFeeQuickFill;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

// Quick fill for Offer Creation.
// Code By : Dharma raj	
// Date    : 25/09/2207

function setContactFeeQuickFill(){
	if (xmlHttp.readyState == 4){ 
		var cf = xmlHttp.responseText;
		document.getElementById('quickFillspnContactFee').value = formatCurrency(cf);
	}
}

// Quick fill for Offer Creation.
// Code By : Dharma raj	
// Date    : 25/09/2207

function syncFiledsquickFill(soruce, target){
		$(target).value = soruce.value;	
}

function setContactFee(){
	if (xmlHttp.readyState == 4){ 
		var cf = xmlHttp.responseText;
		document.getElementById('spnContactFee_' + varSpnId).innerHTML = formatCurrency(cf);
		objCosts = document.getElementsByTagName("span");
		tmpSum = 0;
		for(i=0;i<objCosts.length;i++){
			tmpCost = parseFloat(objCosts[i].innerHTML);	
			if(!isNaN(tmpCost))
				tmpSum += tmpCost;
		}
		document.getElementById("totalCost").innerHTML = formatCurrency(tmpSum);
		document.getElementById("offersCost").value = formatCurrency(tmpSum);
	}
}

function getIndex(what,which) {
    for (var i=0;i < what.elements.length;i++)
        if (what.elements[i].name == which)
            return i;
    return -1;
}


function validateOffer(){
	with(document.frmOffer){
		for(i=0;i<elements.length;i++){
			
			if(elements[i].type == 'select-one' && elements[i].title == 'stockitem' && elements[i].value == '0'){
					alert("You've not selected a stock item for one of more offers");
					elements[i].focus();
					return false;
			}
			if(elements[i].type == 'text' && elements[i].title == 'offerprice' && trim(elements[i].value) == ''){
					alert("Please enter your offer price");
					elements[i].focus();
					return false;
			}
			else if(elements[i].title == 'offerprice' && isNaN(elements[i].value)){
					alert("There appears to be something wrong with one of the prices? Maybe a stray letter or something?");
					elements[i].focus();
					return false;
			}
			if(elements[i].type == 'text' && elements[i].title == 'offerquantity' && trim(elements[i].value) == ''){
					alert("Please enter your offer quantity");
					elements[i].focus();
					return false;
			}
			else if(elements[i].title == 'offerquantity' && isNaN(elements[i].value)){
					alert("Please enter valid offer quantity");
					elements[i].focus();
					return false;
			}
			//Code uncommented and edited by Ranjithkumar R on 20-09-2007 07.30pm
			if(elements[i].type == 'select-one' && elements[i].title == 'paylmenttemplate' && elements[i].value == '0'){
					alert("Please select your payment option");
					elements[i].focus();
					return false;
			}
		

		}
		target = "_parent";
	}
	if(document.getElementById('offerCount_for_js_validation').value == 0){
		alert("Whoa. There are no buyers to send an offer to!");
		return false;
	}
	return true;
}

// Quick fill for Offer Creation.
// Code By : Dharma raj	
// Date    : 25/09/2207

function quickFillFunc(){ 
	with(document.frmOffer){
		for(i=0;i<elements.length;i++){
		argConter = 0;
		argConter = elements[i].alt;
			if(elements[i].type == 'select-one' && elements[i].title == 'stockitem'){
					quickStockItem = document.quickFill.qfillstock_id.value;
					elements[i].value = quickStockItem;
			}
			if(elements[i].type == 'text' && elements[i].title == 'offerprice'){
					quickOfferPrice = document.quickFill.qfillPrice.value;
					elements[i].value = quickOfferPrice;
			}        
			if(elements[i].type == 'hidden' && elements[i].title == 'offerquantity'){
					quickQty = document.quickFill.qfillqty.value;
/*					totalCostOne = parseFloat(document.getElementById("quickFillspnContactFee").value);*/
					elements[i].value = quickQty;
					argElem = elements[i].alt;
					contactCost = document.getElementById("contCost_"+argElem).value;
					document.getElementById("spnContactFee_"+argElem).innerHTML = formatCurrency(quickQty*contactCost);
			}
			if(elements[i].type == 'select-one' && elements[i].title == 'ExpireDay'){
					quickExpDay = document.quickFill.qfilloffer_expires_in.value;
					elements[i].value = quickExpDay;
			}
			if(elements[i].type == 'checkbox' && elements[i].title == 'bestOffer'){
					if(document.quickFill.quick_best_offer.checked == true){
						elements[i].checked = true;
					}else{
						elements[i].checked = false;
					}
			}			
			if(elements[i].type == 'select-one' && elements[i].title == 'paylmenttemplate'){
					quickPayTemplate = document.quickFill.qfillpayment_template_id.value;
					elements[i].value = quickPayTemplate;
			}
		}
		
		objCosts = document.getElementsByTagName("span");
		tmpSum = 0;
		for(i=0;i<objCosts.length;i++){
			tmpCost = parseFloat(objCosts[i].innerHTML);	
			if(!isNaN(tmpCost))
				tmpSum += tmpCost;
			}
		document.getElementById("totalCost").innerHTML = formatCurrency(tmpSum);
		document.getElementById("offersCost").value = formatCurrency(tmpSum);		
		
	}
	return false;
}

function checkField(curObj){
	if(isNaN(curObj.value)){
		var val = curObj.value
		alert("Please enter only numbers.");
		//curObj.value = val.substr(0,(val.length)-1);
		curObj.value = '';
		document.getElementById("quantityQF").value = '';
		
		return false;
	}
}

function validateOfferView(source, index){
	//alert(source);
	$('view_id').value 		= $(source).value;
	$('view_index').value 	= index-1;
	if($(source).value == '0'){
		alert("Please select your stock item");
		return false;
	}
	$('frmOffer').target = "_blank";
	return true;
}

function removeRow(src){
	
	offerTbl	= document.getElementById('offerTable');
	var userAgent=navigator.userAgent;
	   if (userAgent.indexOf('Firefox') != -1) {
		  offerTbl.deleteRow(src.parentNode.parentNode.rowIndex);
	   }
	   else{
		 var current = window.event.srcElement;
    	 while ( (current = current.parentNode)  && current.tagName !="TR");
         current.parentNode.removeChild(current);

	   }
	$('totalOffers').innerHTML = parseInt($('totalOffers').innerHTML) - 1;
	document.getElementById('offerCount_for_js_validation').value = parseInt($('totalOffers').innerHTML);
	tmpSum = 0;
	objCosts = document.getElementsByTagName("span");
	for(i=0;i<objCosts.length;i++){
		tmpCost = parseFloat(objCosts[i].innerHTML);	
		if(!isNaN(tmpCost))
			tmpSum += tmpCost;
	}
	$("totalCost").innerHTML 	= roundNumber(tmpSum,2);
	$("offersCost").value 		= roundNumber(tmpSum,2);
}

// End Offer Management

//Feed back
// Ramesh Murugan
function replyTo(id){
	tmpDiv = document.getElementById("div_"+id);
	tmpDiv.style.position = 'static';
	tmpDiv.style.visibility = 'visible';
}

function cancelReplyTo(id){
	tmpDiv = document.getElementById("div_"+id);
	tmpDiv.style.position = 'absolute';
	tmpDiv.style.visibility = 'hidden';
}

var varFeedCurId = 0;
var varFeedCurMsg = '';
var varFeedCurRec = '';

function saveNegFeedback(argId, argFeedId, argReplyMsg, argReceivedBy ){

	varFeedCurId 	= argId;
	varFeedCurMsg	= argReplyMsg;
	varFeedCurRec	= argReceivedBy;

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	
	var url="negativefeedback.php?feedbackId=" + argFeedId + "&replymsg=" + argReplyMsg;
	xmlHttp.onreadystatechange=savedNegFeed;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function savedNegFeed(){
	if (xmlHttp.readyState==4){ 
		var result = xmlHttp.responseText;
		document.getElementById('div_'+ varFeedCurId).innerHTML = '<b>' + varFeedCurRec +'\'s reply :</b> ' + varFeedCurMsg;
		document.getElementById('lnk_'+ varFeedCurId).style.position = 'absolute';
		document.getElementById('lnk_'+ varFeedCurId).style.visibility = 'hidden';
		alert(result);
	}
 //cancelReplyTo(varFeedCurId);
}
// End of feedback
/*  Author(s)		-	Mujifur Rahman */

function viewReply(frm)
{
  frm.action="index.php?pgtp=replymessage";
  frm.submit();
}

function setPaymentAction()
{
	alert('Create Payment Terms Before Creating Offers !');
	document.getElementById("findbuyers").action = 'index.php?pgtp=salesterms';
	document.getElementById("findbuyers").submit();
}

function cancelCreateMessage(frm,retPage)
{
//frm.subject.value="";
//frm.message.value="";
//frm.emailcopy.checked=false;
//frm.attachment.value="";
//document.getElementById("cancel_frm").action=
frm.action="index.php?pgtp="+ retPage;
return true;
}


function createMessageValidate(frm)
{

	if(trim(frm.subject.value)=="")
	{
	alert("Please enter the subject");
	frm.subject.focus();
	return false;
	}
	if(!limitSpecialChar(frm.subject)){
		alert("Special charecters not allowed in Subject.");
		frm.subject.focus();
		return false;
	}
	if((trim(frm.subject.value).length)>100)
	{
	alert("Subject should be maximum of 100 characters !");
	frm.subject.focus();
	return false;
	
	}
	if(trim(frm.message.value)=="")
	{
	alert("Please enter the message");
	frm.message.focus();
	return false;
	}
	if (frm.message.value.length > 5000){
		alert("Message should be maximum of 5000 characters !");
		frm.message.focus();
		return false;
	}
	//if(!limitSpecialChar(frm.message)){
//		frm.message.focus();
//		return false;
//	}
	return true;
}

function blockConfirm()
{
	if(confirm(" Do you want to block this user ? "))
	return true;
	else
	return false;
}
function deleteMessageConfirm()
{
	if(confirm(" Do you want to delete this message ? "))
	return true;
	else
	return false;
}


function scrollToBottom()
 {
	if(document.getElementById("message")!=null){
	  tag=document.getElementById("message");
	  tag.scrollTop = tag.scrollHeight;
	}
}

function replyMessageValidate(frm)
{
	if(trim(frm.message.value)=="")
	{
	alert("Please enter the message");
	frm.message.focus();
	return false;
	}
	//if(!limitSpecialChar(frm.message)){
//		frm.message.focus();
//		return false;
//	}
	return true;
}

function cancelReply(frm)
{
	frm.action="index.php?pgtp=viewmessage";
	frm.submit();
	return false;
}

function contactSubmit(frmx)
{
	frmx.action = "index.php?pgtp=createmessage";
	if(typeof(frmx.pgtp) != undefined ){
		frmx.pgtp.value = "createmessage";
	}
	return true;
}

function downloadAttachment(tag)
{
 tag.submit();
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+''+
		num.substring(num.length-(4*i+3));
		return (((sign)?'':'-') + num + '.' + cents);
}

function calcPrice(price)
{
	if((isNaN(price))||(price==""))
		price=0;
		
	if(document.getElementById("yourPrice")){
		if(document.getElementById("yourPrice").value != ''){
			var offerPrice = parseFloat(document.getElementById("yourPrice").value);
			tot = offerPrice + parseFloat(price);
			if(document.getElementById("hiddMinPrice")){
				document.getElementById("hiddMinPrice").value = formatCurrency(parseFloat(price));
			}
			
			document.getElementById('minPandP').innerHTML = formatCurrency(price);
			document.getElementById('Totalcost').innerHTML = formatCurrency(parseFloat(tot));
			document.getElementById("cost").value = formatCurrency(parseFloat(tot));		
		}
	}else{
	var offerPrice = parseFloat(document.getElementById("costHid").value);
	tot = offerPrice + parseFloat(price);
	document.getElementById('minPandP').innerHTML = formatCurrency(price);
	document.getElementById('Totalcost').innerHTML = formatCurrency(parseFloat(tot));
	document.getElementById("cost").value = formatCurrency(parseFloat(tot));
	}
}

function priceUpdate(currValue){
	var minVal;
	if(document.getElementById("hiddMinPrice")==null)
		var minVal =0;
	else
		var minVal = document.getElementById("hiddMinPrice").value;
	document.getElementById('negoPrice').innerHTML = formatCurrency(parseFloat(currValue)); 
	 var totVal = (parseFloat(minVal)+parseFloat(currValue));
	 document.getElementById("Totalcost").innerHTML = formatCurrency(totVal);
	 document.getElementById("cost").value = formatCurrency(totVal);
}


function delAddress(){

	//The below line is bloceked by Karthikeyan R on 18-July-08 to avoid the javascript error msg.
	//===========================================================================================
	//$("errorMsg").innerHTML = '';

	$('uname').value = trim($F('fname'))+" "+trim($F('sname'));
	if($F('yourPrice')){
		if(!allValidNumber($F('yourPrice'))){
			
		Focuson_TXTname="yourPrice";		
		Common_AlertBox('Accept offer','<div align=center style=\'margin-top:20px;\'>Invalid price</div>','','OK',300,40);	
			
			/*alert("Invalid price");
			$('yourPrice').focus();*/
			return false;		
		}
		if(trim($F('yourPrice')) == "" || trim($F('yourPrice')) == 0){
		Focuson_TXTname="yourPrice";		
		Common_AlertBox('Accept offer','<div align=center style=\'margin-top:20px;\'>Please enter price</div>','','OK',300,40);
			/*alert("Please enter price");
			$('yourPrice').focus();*/
			return false;		
		}
	}
	if($F('negoExpire')){
		if(trim($F('negoExpire')) == 0 ){
		Focuson_TXTname="negoExpire";		
		Common_AlertBox('Accept offer','<div align=center style=\'margin-top:20px;\'>Please select expire days</div>','','OK',300,40);
			/*alert("Please select expire days");
			$('negoExpire').focus();*/
			return false;		
		}
	}
	
	if(trim($F('fname')) == "" ){
		Focuson_TXTname="fname";		
		Common_AlertBox('Delivery address','<div align=center style=\'margin-top:20px;\'>You seem to have missed out your firstname! Please add it in</div>','','OK',380,40);
		/*alert("You seem to have missed out your firstname! Please add it in");
		$('fname').focus();*/
		return false;		
	}
	
	/*if(trim($F('sname')) == "" ){
		alert("Whoops. You've not included your surname, can you add it in please");
		$('sname').focus();
		return false;		
	}
	*/

	if(trim($F('address1'))=="" && trim($F('address2'))=="" && trim($F('address3'))==""){
		Focuson_TXTname="address1";		
		Common_AlertBox('Delivery address','<div align=center style=\'margin-top:20px;\'>Waaa! There\'s no address! The seller is going to have some problems shipping the item to you! If you include you address, that would be just great</div>','','OK',460,50);
		
		/*alert("Waaa! There's no address! The seller is going to have some problems shipping the item to you! If you include you address, that would be just great");
		$('address1').focus();*/
		return false;		
	}
	if(trim($F('city'))==""){
		Focuson_TXTname="city";		
		Common_AlertBox('Delivery address','<div align=center style=\'margin-top:20px;\'>Please enter the city</div>','','OK',300,40);
		/*alert("Please enter the city");
		$('city').focus();*/
		return false;		
	}
	
	
	if(!allValidAlph($F('city'))){
		Focuson_TXTname="city";		
		Common_AlertBox('Delivery address','<div align=center style=\'margin-top:20px;\'>Invalid city name</div>','','OK',300,40);
		/*alert("Invalid city name");
		$('city').focus();*/
		return false;		
	}
		
	
	if(trim($F('zip_code'))==""){
		Focuson_TXTname="zip_code";		
		Common_AlertBox('Delivery address','<div align=center style=\'margin-top:20px;\'>Please enter the postal code</div>','','OK',300,40);
		/*alert("Please enter the postal code");
		$('zip_code').focus();*/
		return false;		
	}
	if(IsAlphaNumeric($F('zip_code'))){
		Focuson_TXTname="zip_code";		
		Common_AlertBox('Delivery address','<div align=center style=\'margin-top:20px;\'>Invalid postal code</div>','','OK',300,40);
		/*alert("Invalid postal code");
		$('zip_code').focus();*/
		return false;		
	}
	if(trim($F('country')) == 0 ){
		Focuson_TXTname="country";		
		Common_AlertBox('Delivery address','<div align=center style=\'margin-top:20px;\'>Please select the country</div>','','OK',300,40);
		/*alert("Please select the country");
		$('country').focus();*/
		return false;		
	}
	
	
	if(!allValidNumber($F('cost'))){
		Focuson_TXTname="cost";		
		Common_AlertBox('Accept offer','<div align=center style=\'margin-top:20px;\'>Invalid price</div>','','OK',300,40);
		/*alert("Invalid price");
		$('cost').focus();*/
		return false;		
	}
	if(trim($F('cost')) == ""){
		Focuson_TXTname="cost";		
		Common_AlertBox('Accept offer','<div align=center style=\'margin-top:20px;\'>Please enter price</div>','','OK',300,40);
		/*alert("Please enter price");
		$('cost').focus();*/
		return false;		
	}

	
}
function onclickCon(actUrl){
	if(actUrl != ""){
		document.getElementById("frmwanted").action = actUrl;	
		// Don't be remove the comment : It will rise problem in crome
		//document.getElementById("frmwanted").submit();
	}
}

function retractNegoConfim(actUrl){

	if(confirm("Do you want retract this negotiation?")){
		if(actUrl != ""){
			//the below line is added by Karthikeyan R on 03-Mar-09 to fix the submit issue in chrome and safari
			document.frmwanted.retractNego.value='41';		
			document.getElementById("frmwanted").action = actUrl;
			document.getElementById("frmwanted").submit();
			//return true;
		}
	}
	else{
		return false;
	}
}
function onclickConDelete(actUrl){
	if(confirm("Do you want delete this Offer ? "))
	{
		if(actUrl != ""){
			document.getElementById("frmwanted").action = actUrl;
			return true;
		}
	}
	return false;
}
function onclickConTop(actUrl){

	if(actUrl != ""){
		document.getElementById("frmwantedTop").action = actUrl;	
		//document.getElementById("frmwantedTop").submit();
		//return false;
	}
}
function onclickFeed(actUrl,user){
	if(actUrl != ""){
		
		document.findbuyers.feed_user_id.value=user;
		
		document.getElementById("findbuyers").action = actUrl;
		document.getElementById("findbuyers").submit();
	}
}
function onclickFeedBuyer(actUrl,user){
	if(actUrl != ""){
		document.buyhisfeed.feed_user_id.value=user;
		document.getElementById("buyhisfeed").action = actUrl;
		document.getElementById("buyhisfeed").submit();
	}
}

function salesPayLink(val)
{
	 
	 document.getElementById("slctTemplates").value=val;
	 document.salespay.submit();
	 //document.getElementById("salespay").submit();
	 
}


function alertView(tag)
{
	tag.form.action="index.php?pgtp=alertview";
	return true;
}

function resetChilds(grandParent){
	var flag;
	with(document.findbuyers){
		for(i=0;i<elements.length;i++){
			var count;
			var len;
			if(elements[i].type != 'select-one'){
				flag=-1;break;
			}
			if(flag!=-1){
			flag=flag+1;
			}
			if(flag>=3){
				//alert(elements[i].options.length);
				//alert(elements[i].name);
				//elements[i].innerHTML='<option value=0 >Any / Don\'t Mind</option>';
			
			len=elements[i].options.length;
			lent=len-1;
			//alert(len);
			//document.elements[i].options[lent].selected=true;
			//alert(document.elements[i].options[lent]);
    		for (count = 0 ;  count<len ; count++) {
				if(count!=0){
					//alert(count);
					//alert(elements[i].options);
					elements[i].options[count]=null;// (count);
				}
    		}
			if( elements[i].id != "condition")
			elements[i].disabled=true;
				//elements[i].value = 0;
				//elements[i].text = 'Any/Dont mind';
			}
			
			if((elements[i].type == 'select-one')&&(elements[i].name==grandParent)){
				flag=1;
			}
			
			
		}
	}
	//alert(grandParent);
}


function refineSearch()
	{
		
		var attribvalids="";
		
	with(document.refine){
		for(i=0;i<elements.length;i++){
			if((elements[i].type == 'select-one')&&(elements[i].value!='')){
				attribvalids=attribvalids+elements[i].value+"-";
			}
		}
	}
	xmlHttp1=GetXmlHttpObject();
	if (xmlHttp1==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	<!--attribgrpid="+atrid+"&srchval="+str-->
	var url="refinesearch.php?attribvalids="+attribvalids;
	var url_length=url.length-1;
	url=url.substring(0,url_length);
	//alert(url);
	xmlHttp1.onreadystatechange=searched;
	xmlHttp1.open("GET",url,true);
	xmlHttp1.send(null);
	} 

	function searched() 
	{ 
		if (xmlHttp1.readyState==4)
		{ 
		var result = xmlHttp1.responseText;
		if(result != ''){
				
				document.getElementById("refine_search1").innerHTML=xmlHttp1.responseText;
			}else{
				document.getElementById("refine_search1").innerHTML = 'No Products';				
			}
		}
	}


	function str_replace_reg(haystack, needle, replacement) {
		var r = new RegExp(needle, "g");
		alert(r);
		return haystack.replace(r, replacement);
	}


	/*function refineSearchNew(template_id,reference,tmpSearchTerms,tmpCatSearchTerms,tmptemSearchTerms,pageno,noOfRecords,moto,grpids)
	{
		
		var attribvalids="";
	
		if(tmptemSearchTerms == '')
		{		for(i=8;i<(arguments.length);i++){
					if(document.getElementById(arguments[i]).value!='')
						attribvalids=attribvalids+"_V"+document.getElementById(arguments[i]).value+"_V-";
				
				}
		}
	// Modified for URL - Rewriting - Ramesh Murugan
	tmpCatId = document.frmPage.category_id.value;
	
	//with(document.refine){
//		for(i=0;i<elements.length;i++){
//			//alert(elements[i].value);
//			if((elements[i].type == 'select-one')&&(elements[i].value!='')){
//				attribvalids=attribvalids+"_V"+elements[i].value+"_V-";
//			}
//		}
//	}

	alert(tmpSearchTerms);
	tmpCatSearchTerms = str_replace_reg(tmpCatSearchTerms,"&quot;","\"");
	tmptemSearchTerms = str_replace_reg(tmptemSearchTerms,"&quot;","\"");
	tmpSearchTerms = str_replace_reg(tmpSearchTerms,"&quot;","\"");
	
	alert(tmpSearchTerms);
	xmlHttp1=GetXmlHttpObject();
	if (xmlHttp1==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	<!--attribgrpid="+atrid+"&srchval="+str-->
	// Modified for URL - Rewriting - Ramesh Murugan
	var url= jsVarServerPath + "refinesearchnew.php?template_id="+template_id+"&reference="+reference+"&tmpSearchTerms="+tmpSearchTerms+"&tmpCatSearchTerms="+tmpCatSearchTerms+"&tmptemSearchTerms="+tmptemSearchTerms+"&pageno="+pageno+"&noOfRecords="+noOfRecords+"&moto="+moto+"&attribvalids="+attribvalids + "&category_id=" + tmpCatId ;
	//var url_length=url.length-1;
	//url=url.substring(0,url_length);
	alert(url);
	xmlHttp1.onreadystatechange=searchedNew;
	xmlHttp1.open("GET",url,true);
	xmlHttp1.send(null);
	} */

	var attrPos = 0;
	var orderBy = 'price';
	var orderByClaus = 'desc';
	var varFromLink = false;
	function refineSearchNew(template_id,reference,tmpSearchTerms,tmpCatSearchTerms,tmptemSearchTerms,pageno,noOfRecords,moto,grpids)
	{
		
		var attribvalids="";
		var price =0;
		if(tmptemSearchTerms == '')
		{		for(i=8;i<(arguments.length);i++){
					if(document.getElementById(arguments[i]).value!='')
						attribvalids=attribvalids+"_V"+document.getElementById(arguments[i]).value+"_V-";
				
				}
		}
	// Modified for URL - Rewriting - Ramesh Murugan
	tmpCatId = document.frmPage.category_id.value;
	
	/*alert(tmpSearchTerms);
	tmpCatSearchTerms = str_replace_reg(tmpCatSearchTerms,"&quot;","\"");
	tmptemSearchTerms = str_replace_reg(tmptemSearchTerms,"&quot;","\"");
	tmpSearchTerms = str_replace_reg(tmpSearchTerms,"&quot;","\"");
	
	alert(tmpSearchTerms);*/
	tmpPrice = 0;
	if(document.getElementById("drpPrice"))
		tmpPrice = document.getElementById("drpPrice").value;
	if(varFromLink)
	{
		if(orderByClaus == "desc")
			orderByClaus = "asc";
		else	
			orderByClaus = "desc";
	}
	varFromLink = false;	
	var url= jsVarServerPath + "refinesearchnew.php?template_id="+template_id+"&reference="+reference+"&tmpSearchTerms="+tmpSearchTerms+"&tmpCatSearchTerms="+tmpCatSearchTerms+"&tmptemSearchTerms="+tmptemSearchTerms+"&pageno="+pageno+"&noOfRecords="+noOfRecords+"&moto="+moto+"&attribvalids="+attribvalids + "&price=" + tmpPrice + "&category_id=" + tmpCatId + "&orderby=" + orderBy + "&orderclause=" + orderByClaus + "&attributePos=" + attrPos;
	//var url= jsVarServerPath + "refinesearchnew.php?tmpSearchTerms="+tmpSearchTerms;
	//alert(url);
	ajaxrequest(url,"searchedNew",'',0);	
	}
	
	
	function searchedNew(result,obj) 
	{ 
		
		//alert(result);
		if(result != ''){
				document.getElementById("refine_search1").innerHTML=result;
			}else{
				document.getElementById("refine_search1").innerHTML = 'No Products';				
			}
	}
	
	/*function searchedNew() 
	{ 
		
		if (xmlHttp1.readyState==4)
		{ 
		var result = xmlHttp1.responseText;
		alert(result);	
		if(result != ''){
				document.getElementById("refine_search1").innerHTML=result;
			}else{
				document.getElementById("refine_search1").innerHTML = 'No Products';				
			}
		}
	}
	*/
	function searchPaging(pageno,noofrecords,reversing,moto,txtSearch)
	{
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	<!--attribgrpid="+atrid+"&srchval="+str-->
	var url="searchpaging.php?pageno="+pageno+"&noofrecords="+noofrecords+"&reverse="+reversing+"&moto="+moto+"&txtSearch="+txtSearch;
	xmlHttp.onreadystatechange=paged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	} 
	
	function paged() 
	{ 
		if (xmlHttp.readyState==4)
		{ 
		var result = xmlHttp.responseText;
		if(result != ''){
				
				document.getElementById("refine_search1").innerHTML=xmlHttp.responseText;
			}else{
				document.getElementById("refine_search1").innerHTML = 'No Products';				
			}
		}
	}
	
	
	function searchPagingNew(pageno,noofrecords,reversing)
	{
	var attribvalids="";
		
	with(document.refine){
		for(i=0;i<elements.length;i++){
			if((elements[i].type == 'select-one')&&(elements[i].value!='')){
				attribvalids=attribvalids+"_V"+elements[i].value+"_V-";
			}
		}
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	<!--attribgrpid="+atrid+"&srchval="+str-->
	var url="searchpagingnew.php?pageno="+pageno+"&noofrecords="+noofrecords+"&reverse="+reversing+"&attribvalids"+attribvalids;
	xmlHttp.onreadystatechange=pagedNew;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	} 

	function pagedNew() 
	{ 
		if (xmlHttp.readyState==4)
		{ 
		var result = xmlHttp.responseText;
		if(result != ''){
				
				document.getElementById("refine_search1").innerHTML=xmlHttp.responseText;
			}else{
				document.getElementById("refine_search1").innerHTML = 'No Products';				
			}
		}
	}
	
	function calContactCost(wanted_ad_id,state,cost, price)
	{
		var	action
	if(state==true){
		action = 'add';
	}
	else{
		action = 'delete';
		document.getElementById("all").checked=false;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	<!--attribgrpid="+atrid+"&srchval="+str-->
	var url="contactcost.php?wanted_ad_id="+wanted_ad_id+"&action="+action+"&cost="+document.getElementById("cost"+wanted_ad_id).value + "&price=" + document.getElementById("price"+wanted_ad_id).value;
	xmlHttp.onreadystatechange=setConCost;
	
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	} 

	function setConCost() 
	{ 
		if (xmlHttp.readyState==4)
		{ 
		var result = xmlHttp.responseText;
		if(result != ''){
				//alert(result);
				document.getElementById("contact").innerHTML=formatCurrency(xmlHttp.responseText);
			}else{
				document.getElementById("contact").innerHTML = '0.00';				
			}
		}
	}
	
var CldDiv;
function getChildDiv(ParentValueId,ChildDiv,GroupId,AllGroupIds)
	{
	/*if(){
		if(document.getElementById(testone).style.display=='none')
		{
			document.getElementById(testone).style.display=""
		}
	else
		{
			document.getElementById(testone).style.display="none"
		}	
	}*/
	CldDiv=ChildDiv;	
	xmlHttp2=GetXmlHttpObject();
	if (xmlHttp2==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	<!--attribgrpid="+atrid+"&srchval="+str-->
	// Modified for URL - Rewriting - Ramesh Murugan
	var url=jsVarServerPath + "specificchilddiv.php?group_id="+GroupId+"&ParentValueId="+ParentValueId + "&AllGroupIds=" +  AllGroupIds;
	//alert(url);
	xmlHttp2.onreadystatechange=displayChildDiv;
	xmlHttp2.open("GET",url,true);
	xmlHttp2.send(null);
	} 

	function displayChildDiv() 
	{ 
		if (xmlHttp2.readyState==4)
		{ 
		var result = xmlHttp2.responseText;
		if(result != ''){
			//alert(CldDiv);
			//alert(result);
			document.getElementById('div'+CldDiv).innerHTML=xmlHttp2.responseText;
			CldDiv='';
			}
		}
	}


var CldAllDiv;
function getAllChildDiv(ParentAssignId,ChildDiv,GroupId)
	{
	
	CldAllDiv=ChildDiv;	
	xmlHttp2=GetXmlHttpObject();
	if (xmlHttp2==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	<!--attribgrpid="+atrid+"&srchval="+str-->
	var url="childalldiv.php?group_id="+GroupId+"&ParentAssignId="+ParentAssignId;
	//alert(url);
	xmlHttp2.onreadystatechange=displayAllChildDiv;
	xmlHttp2.open("GET",url,true);
	xmlHttp2.send(null);
	} 

	function displayAllChildDiv() 
	{ 
		if (xmlHttp2.readyState==4)
		{ 
		var result = xmlHttp2.responseText;
		if(result != ''){
			//alert(CldDiv);
			//alert(result);
			document.getElementById('div'+CldAllDiv).innerHTML=xmlHttp2.responseText;
			CldAllDiv='';
			}
		}
	}

	/*var SpecificCldDiv;
function getSpecificChildDiv(ParentAssignId,ChildDiv,GroupId)
	{
		alert("");
	SpecificCldDiv=ChildDiv;	
	xmlHttp2=GetXmlHttpObject();
	if (xmlHttp2==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	<!--attribgrpid="+atrid+"&srchval="+str-->
	var url="specificchilddiv.php?group_id="+GroupId+"&ParentAssignId="+ParentAssignId;
	//alert(url);
	xmlHttp2.onreadystatechange=displaySpecificChildDiv;
	xmlHttp2.open("GET",url,true);
	xmlHttp2.send(null);
	} 

	function displaySpecificChildDiv() 
	{ 
		if (xmlHttp2.readyState==4)
		{ 
		var result = xmlHttp2.responseText;
		if(result != ''){
			//alert(CldDiv);
			//alert(result);
			document.getElementById('div'+SpecificCldDiv).innerHTML=xmlHttp2.responseText;
			SpecificCldDiv='';
			}
		}
	}*/
	
	
	function checkProductConfigure()
	{
		
		var error=0;
	with(document.product_configure){
		for(i=0;i<elements.length;i++){
			if(error!=1)
			{
				if((elements[i].type == 'select-one')&&(elements[i].value=='')){
					error=1;
				}
			}
		}
	}
	if(error==0){
		return true;
	}
	
	else
	{
		return false;
	}
	}
function SbtFrm(page)
{
	//document.product_configure.onsubmit=checkProductConfigure();	
	if(checkProductConfigure())
	{
		
		if(page=='sell')
		{	// Modified by Ramesh Murugan - FOR URL rewriting
			document.product_configure.action= jsVarServerPath + "index.php?pgtp=stockcreate";
			document.product_configure.method="post"
			document.product_configure.submit();
		}
		else
		{
			
			document.product_configure.action=jsVarServerPath + "index.php?pgtp=newwantedad";
			document.product_configure.method="post"
			document.product_configure.submit();
		}
	}
	else
	{
		alert('Select The Attributes Or Try Other Links');
	}
		
	}
	
	//The below 2 functions are moved to search_aroxo.js by Karthikeyan R on 03-N0v-09
	//================================================================================

	/*	
	function trim_search(str) {     
		if(!str || typeof str != 'string')        
		return null;   
		return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
		}
	
function checkSearchKey()
{
	
	error=0;
	var textBox=document.searchfrm.txtSearch;
	//alert(textBox) 
	var textValue=textBox.value;
	if(textValue==null){ 
		error=1;
	}
	if(!checkValid(textValue,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890./_-" ')) { 
	alert('Sorry, but we detected a character in your search term which our system didn\'t like :(');
	document.searchfrm.txtSearch.focus();
	return false;
	}
	if(textBox.value.length<2)
	{
		error=1;
		
	}
	if(error==0){
		
		return true;
	}
	
	else
	{
		alert('We need a little more to go on!');
		document.searchfrm.txtSearch.focus();
		return false;
	}
}*/
function checkSearchKey1()
{
	
	error=0;
	var textBox=document.searchfrm1.txtSearch;
	//alert(textBox)
	var textValue=textBox.value;
	if(textValue==null){ 
		error=1;
	}
	if(!checkValid(textValue,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890./_- ')) { 
	alert('Sorry, but we detected a character in your search term which our system didn\'t like :(');
	document.searchfrm.txtSearch.focus();
	return false;
	}
	if(textBox.value.length<2)
	{
		error=1;
		
	}
	if(error==0){
		
		return true;
	}
	
	else
	{
		alert('We need a little more to go on!');
		document.searchfrm.txtSearch.focus();
		return false;
	}
}
function checkCmsSearchKey()
{
	error=0;
	var textBox=document.tsearch.key;
	if((trim(textBox.value)=='')||(trim(textBox.value).length<2))
	{
		error=1;
		
	}
	if(error==0){
		return true;
	}
	else
	{
		alert('We need a little more to go on!');
		document.tsearch.key.focus();
		return false;
	}
}

function checkChar(str){
	if(str.value != ''){
		if(!checkValid(str.value,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 ')){
			alert("Special charecters not allowed.");
			str.value = '';
			return false;	
		}
		else{ return true; }
	}
} 

function checkSearchBuy()
{
	error=0;
	var textBox=document.frmSearchBuy.txtSearch;
	if((textBox.value=='')||(textBox.value.length<2))
	{
		error=1;
	}
	if(error==0){
		return true;
	}
	
	else
	{
		alert('We need a little more to go on!');
		document.frmSearchBuy.txtSearch.focus();
		return false;
	}
}

function limitSpecialChar(varObject)
{
	
	
 if(!checkValid(varObject.value,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.,?:/!$%()>\n\t`\"\'- '))
  {
			
			return false;	
  }
  return true; 
  
	
}
function limitText(currObj){
	strlenth = currObj.value.length;
	
    if(!checkValid(currObj.value,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.;,?:/!$%()>£$% \\n \t `\"\'\`-   ')){
			//alert("Special charecters & numbers not allowed.");
			alert("We've detected some characters which we don't support in your notes. Sorry");
			currObj.focus();
			return false;	
	}
	if(strlenth <= 200){
		return true;
	}else{
		if(strlenth > 200);
		{
			var str = currObj.value;
			cutstr = str.substr(0,200);
			currObj.value = cutstr; 
			return true;
		}
		alert("Text should not have more then 200 characters.");
		return false;
	}
}

function isAppAcceptText(argvalue){
	if(!checkValid(argvalue,glAppAcceptText)){
			return false;	
	}
	return true;
} 

function isAppAcceptLine(argvalue)
{   
	if(!checkValid(argvalue,glAppAcceptLine)){
			return false;	
	}
	return true;
}

function isAppAcceptNumericLine(argvalue)
{   
	if(!checkValid(argvalue,glAppAcceptNumericLine)){
			return false;	
	}
	return true;
}

function viewStockPage(frm_id)
{
alert(document.getElementById(frm_id));
}

function priceCheck(argAssignId,argNxtGrpId,argTempalteId,argCount,argCurrentDiv){
	//alert("AssignId-"+argAssignId+"  Next GroupId-"+argNxtGrpId+" templateId-"+argTempalteId+" totalCount-"+argCount+" currentDiv-"+argCurrentDiv);
	var valueList = new Array();
	new Ajax.Request('pricecheckajax.php', {
	method:'post',
	parameters: {assignId: argAssignId,nextGrpId:argNxtGrpId,templateId:argTempalteId,count:argCount,currDiv:argCurrentDiv},
	onSuccess: function(optionalFunction){
		valueList = optionalFunction.responseText || "No Data";
		document.getElementById('div_'+argNxtGrpId).innerHTML = valueList;
	},
	onFailure: function(){ alert('Something went wrong...') }
	});			
}

// 30 - August - 2007

function changeAction(action,page){
	
	//alert(page);
	
	page.action=action;
	//page.method="post"
	//page.submit();
	return true;
	//alert(action);
}

function changePageAction(action,page){
	var status=true;
	if(action=='index.php?pgtp=offermanagement')
	status=validateFindBuyers()
	if(status==true){
	document.getElementById(page).action=action;
	document.getElementById(page).submit();
	}
	else{
		return false;
	}
}
function changePageActionView(action,page,WanAdId){
	
	document.getElementById("wanted").value=WanAdId;
	
	document.getElementById(page).action=action;
	document.getElementById(page).submit();
}

function changeGetAction(action,pgtp_value,page){
	page.action=action;
	page.pgtp.value=pgtp_value;
	return true;
}

function selectAllChecks(state,total){
	var action1;
	var url;
	if(state==true){
		action1 = 'add';
	}
	else{
		
		action1 = 'delete';
	}
	
	with(document.findbuyers){
		var nos=0;
		var url='';
		for(i=0;i<elements.length;i++){
			if(elements[i].type=='checkbox'){
				
				if(action1=='add'){
					if(elements[i].checked==true){
						if(elements[i].name!='all'){
							url=url+"wanted_ad_id["+nos+"]="+elements[i].name+"&cost1["+nos+"]="+document.getElementById("cost"+elements[i].name).value+"&";
							nos=nos+1;
						}
					}
					else{
						elements[i].checked=true;
						url=url+"wanted_ad_id["+nos+"]="+elements[i].name+"&";
						nos=nos+1;
					}
				}else{
					//alert(action1);
					elements[i].checked=false;
					url=url+"wanted_ad_id_del["+nos+"]="+elements[i].name+"&";
				}
				
			}
			//alert(elements[i].type);
		}
	}
	url=url+"total="+total;
	//alert(url);
	selectAllCost(url);
}



function selectAllCost(url2)
	{
	
	xmlHttp3=GetXmlHttpObject();
	if (xmlHttp3==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	<!--attribgrpid="+atrid+"&srchval="+str-->
	var url="contactcost.php?"+url2;
	xmlHttp3.onreadystatechange=answer;
	xmlHttp3.open("GET",url,true);
	xmlHttp3.send(null);
	} 

function answer() 
	{ 
		if (xmlHttp3.readyState==4)
		{ 
		var result = xmlHttp3.responseText;
		if(result != ''){
			//alert(CldDiv);
			//alert(result);
			document.getElementById('contact').innerHTML=xmlHttp3.responseText;
			//CldAllDiv='';
			
			}
		}
	}



function validateFindBuyers(){
	var min_price = document.getElementById('minimum_sell_price');
	var flag;
	if(min_price.value != '')
		{
			if(!checkValid(min_price.value,'1234567890.')) { 
				alert("Minimum Sell Price should be number.");
				min_price.focus();
				return false;
				}
		}
		else
		{
			alert("Please enter Minimum Sell Price.");
			min_price.focus();
			return false;
		}
	
		var status=checkSelectedAD();
		if(status==false)
		return false;
		else
		return true;
}

function checkSelectedAD() {
	var flag=0;
	with(document.findbuyers){
		for(i=0;i<elements.length;i++){
			if(elements[i].type=='checkbox'){
				
				if(flag!=1){
					if(elements[i].checked==true){
						if(elements[i].name!='all'){
							flag=1;
						}
						else{
							flag=0;
						}
					}
				}
			}
			  
		}
	}
	if(flag!=1){
		//alert("Select any wantedad for creating offerfdgdfgdfgf");
		alert("Whoa. You need to select some buyers to buyers to send an offer to");
		return false;
	}
	
}

function checkPaymentOptions() {
	var flag=0;
	//alert('');
	/*with(document.salespay){
		for(i=0;i<elements.length;i++){
			alert(elements[i].type);
			if(elements[i].type=='checkbox'){
				
				if(flag!=1){
					if(elements[i].checked==true){
						if(elements[i].name!='all'){
							flag=1;
						}
						else{
							flag=0;
						}
					}
				}
			}
			  
		}
	}*/

	with(document.salespay){
		
		for(i=0;i<elements.length;i++){
			if((elements[i].type=='checkbox') &&(elements[i].name.substr(0,10)=="gatwayname")&&(elements[i].value!=0)&&(elements[i].value!="")){
				//alert(elements[i].name+'    '+elements[i].value);
				//alert(elements[i].name.indexOf("gatwayname"));
				if(flag!=1 && elements[i].checked){
					if(elements[i].value!=0){
							flag=1;
					}
				}
			}
			  
		}
	}
	if(flag!=1){
		//alert("You need to accept at least one of the Aroxo payment options before you can save your payment terms. If you don't use any of these services can we suggest you register for Paypal? ");
		alert('Ooops - there\'s no way a buyer can pay you! Make sure that you have at least one payment mechanism selected');
		return false;
	}
	else{
		return true;
	}
	
}

//Create new stock from offer creation page
function isNewItem(argVal, url, obj){
	if(argVal == 'N'){
		window.location.href = url; 
	}
	else{
		document.getElementById('qfillPrice').value =obj.options[obj.selectedIndex].title;
	}
}
// Function written by Ranjithkumar R on 27-09-2007 04.00pm to validate the feedback form.
function validateFeedback(maxlength){
	//alert(!IsAlphaNumericWithDot(document.getElementById('message').value));
	if((trim(document.getElementById('message').value).length<=0)){
		alert('Please enter the feedback message.');
		document.getElementById('message').focus();
		return false;		
	}
	if((IsAlphaNumericWithSomeSpChar(document.getElementById('message').value))){
		alert('Please enter valid feedback message.[Only alphnumeric with space , - ? ( ) and newline chars allowed.]');
		document.getElementById('message').select();		
		document.getElementById('message').focus();
		return false;
	}
	if($F('message').length > maxlength){
		alert("Please enter less than or equal to " + maxlength + " Characters");
		$('message').focus();
		return false;
	}
	return true;
}

//ajax to delete alert added by vinoth 27/09/2007
var stock_alert_div;

function deleteAlert(stock_id)
	{
	
		
		if(confirm('Are you sure you want to delete alert')){
			stock_alert_div=stock_id;
			xmlHttp4=GetXmlHttpObject();
			if (xmlHttp4==null)
			  {
			  alert ("Your browser does not support AJAX!");
			  return;
			  } 
			
			<!--attribgrpid="+atrid+"&srchval="+str-->
			var url="deletealert.php?stock_id="+stock_id;
			xmlHttp4.onreadystatechange=closeDiv;
			xmlHttp4.open("GET",url,true);
			xmlHttp4.send(null);
			return false;
		}
		else{
			return false;
		}
		
	} 

function closeDiv() 
	{ 
		if (xmlHttp4.readyState==4)
		{ 
		var result = xmlHttp4.responseText;
		if(result != ''){
			//alert(CldDiv);
			//alert(result);

			document.getElementById('manages'+stock_alert_div).style.display='none';
			document.getElementById('stock'+stock_alert_div).innerHTML=xmlHttp4.responseText;
			
			//CldAllDiv='';
			}
		}
	}

function callValidate(tag){
	if(tag.keyCode==13){
		validateWantedForm();
		return false;
	}
	
	//validateWantedForm()
}

/*function countBuyer(argPrice,objData){
	if(isNaN(argPrice)){
		val = objData.value;
		objData.value = val.substr(0,(val.length)-1);
		return false;
	}
	var valueList = new Array();
	new Ajax.Request('countbuyers.php', {
	method:'post',
	parameters: {price: argPrice},
	onSuccess: function(optionalFunction){
		valueList = optionalFunction.responseText || "";
		//alert(valueList);
		//Commented By Ramesh Murugan 15-Jan-09
		//document.getElementById('noOfBuyers').style.display = 'inline';	

		if(!isNaN(valueList)){
			
			if(valueList>100) valueList=100;
			
			valueList=Math.round(valueList);
			old_a= document.getElementById('hid_aDiv').value;
			old_b= document.getElementById('hid_bDiv').value;
		
			cur_a = 100-valueList;
			cur_b =valueList;
		
			document.getElementById('hid_aDiv').value = cur_a;
			document.getElementById('hid_bDiv').value = cur_b;
		
			
				
			//alert("old_a"+old_a);
			///alert("old_b"+old_b);
		
			//alert("value_list"+valueList);

			if(old_b<=valueList){
				//alert("incre");
				
				for(i=old_b;i<=valueList;i++){
					if(i<=100){
						setTimeout('DispMeter1('+i+')',i*10);
					}
				}
			}
			else
			{
				//alert(old_b);
				//alert(valueList);
				//alert("decre");
				
				
				for(i=0,j=old_b;j>valueList;j--,i++){
					if(j>0){
						
						setTimeout('DispMeter2('+j+')',i*10);
						
					}
					
				}
				
			}
		}
		//alert(DispMeter(valueList));
	},
	onFailure: function(){ alert('Something went wrong...') }
	});			
}*/


function countBuyer(argPrice,objData){
		

	if( (document.getElementById("CountStock")) &&
		(document.getElementById("CountStock").value==0) ){
		return false;
	}

	if( (argPrice==null) &&(objData==null) ){
		
		argPrice=document.getElementById("price").value;
	}
	if(argPrice<0){	
		document.getElementById("price").value=0;
		return;
	}
	if(isNaN(argPrice)){
		
		val = objData.value;
		objData.value = val.substr(0,(val.length)-1);
		return false;
	}
	
	var valueList = new Array();
	
	var url="";

	if(document.getElementById("url")){
		url=document.getElementById("url").value+"countbuyers.php";	
	}
	else{
		url="countbuyers.php";
	}

	new Ajax.Request(url, {
	method:'post',
	parameters: {price: argPrice},
	onSuccess: function(optionalFunction){
	
		valueList = optionalFunction.responseText || "";
		//Commented By Ramesh Murugan 15-Jan-09
		//document.getElementById('noOfBuyers').style.display = 'inline';	

		if(!isNaN(valueList)){
		
			if(valueList>100) valueList=100;
			
			valueList=Math.round(valueList);
			old_a= document.getElementById('hid_aDiv').value;
			old_b= document.getElementById('hid_bDiv').value;
		
			cur_a = 100-valueList;
			cur_b =valueList;
		

			document.getElementById('hid_aDiv').value = cur_a;
			document.getElementById('hid_bDiv').value = cur_b;
		
			
				
			//alert("old_a"+old_a);
			///alert("old_b"+old_b);
		
			//alert("value_list"+valueList);

			if(old_b<=valueList){
				//alert("incre");
				
				for(i=old_b;i<=valueList;i++){
					if(i<=100){
						setTimeout('DispMeter1('+i+')',i*10);
					}
				}
			}
			else
			{
				//alert(old_b);
				//alert(valueList);
				//alert("decre");
				
				
				for(i=0,j=old_b;j>valueList;j--,i++){
					if(j>0){
						
						setTimeout('DispMeter2('+j+')',i*10);
						
					}
					
				}
				
			}
		}
		//alert(DispMeter(valueList));
	},
	onFailure: function(){ alert('Something went wrong...') }
	});			
}


function DispMeter1(argValue)
{
	negVal = 100-argValue;
	document.getElementById('aDiv').style.height = negVal+'%';
	document.getElementById('bDiv').style.height = argValue+'%';	
}
function DispMeter2(argValue)
{
	negVal = 100-argValue;
	document.getElementById('aDiv').style.height = negVal+'%';
	document.getElementById('bDiv').style.height = argValue+'%';	
}

function checkNumberOrText(objData){
	if(isNaN(objData.value)){
		val = objData.value;
		objData.value = val.substr(0,(val.length)-1);
		return false;
	}
}



function fnvalidate()
{
	if(document.form1.txtname.value=="")
	{
		alert("Enter Your Name:");
		document.form1.txtname.focus();
		return false;
	}
	
	if(document.form1.txttoname.value=="")
	{
		alert("Enter Your Friends Name:");
		document.form1.txttoname.focus();
		return false;
	}
	if(document.form1.txtto.value=="")
	{
		alert("Enter Your Friends Email-ID:");
		document.form1.txtto.focus();
		return false;
	}
	if(document.form1.txtto.value!="")
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.form1.txtto.value))
		{
		}
		else
		{
			alert("Invalid E-mail Address! Enter Valid MailId");
			document.form1.txtto.focus();
			return false;
		}
	}

	if(document.form1.txtcomments.value=="")
	{
		alert("Enter Your Comments:");
		document.form1.txtcomments.focus();
		return false;
	}
	if(trim($F('humanVerifyCode'))==""){
		alert("Please enter the code you see in the image ");
		$('humanVerifyCode').focus();
		return false;		
	}
}

function storcksearch(frm){
	
	if(frm.stock_search.value == ""){
		alert('Please enter search key word.');
		frm.stock_search.focus();
		return false;	
	}
	if(IsAlphaNumericWithDotSlashHypen(frm.stock_search.value)){
		alert('Please enter valid search key word.[Only alphanumeric with space, slash, hypen and dot(.) allowed].');
		frm.stock_search.focus();
		return false;
	}
	return true;
}

// Function to validate the stock search key
function IsAlphaNumericWithDotSlashHypen(sText) {  	//Match any single non-word characters other than a-zA-Z_0-9 with space.
	reg = /([^a-zA-Z0-9-.\n\r\/ ]+)/;
//	reg = /(^[a-zA-Z ]+$)|(^[a-zA-Z0-9 ]+[\,\s][ a-zA-Z0-9]+)/;
	
	return reg.test(sText);
}

function IsAlphaNumericWithSomeSpChar(sText) {  	//Match any single non-word characters other than a-zA-Z_0-9 with space.
	reg = /([^a-zA-Z0-9-.'?"!;,._+*()\,\n\r ]+)/;
//	reg = /(^[a-zA-Z ]+$)|(^[a-zA-Z0-9 ]+[\,\s][ a-zA-Z0-9]+)/;
	
	return reg.test(sText);
}
/* mujifur */


/*function deleteAlert(alertId,alertType)
{
	  if(confirm('Do you want to delete this Alert.'))
	  {
	  	xmlHttpAlertDelete=GetXmlHttpObject()
	  	url="alertdelete.php"
	  	if (xmlHttpAlertDelete==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	}
  	 
	  	xmlHttpAlertDelete.onreadystatechange=alertDeleted;
	  	xmlHttpAlertDelete.open("POST",url,true);
	  	xmlHttpAlertDelete.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
	  	var post_var;
	  	if(alertType=="system_alert")
	  		post_var='delete_system_alert_x=11&message_alert_id=' + alertId ;
	 	if(alertType=="alert")
	  		post_var='delete_alert_x=11&message_alert_id=' + alertId ;
	
      	xmlHttpAlertDelete.send(post_var);
	  }
}
function alertDeleted() 
{ 
	if (xmlHttpAlertDelete.readyState==4)
	{ 
		var result = xmlHttpAlertDelete.responseText;	
		var result =trim(result);
		if(result!="")
		{
			alertId= result;
			tagId="tr"+alertId;
			document.getElementById(tagId).style.display="none";
		}
	}
} */

/* ---- For deleting alert using ajax -Code by Mujifur -----*/
/* ----                Starting here                     -----*/


function deleteAlert(alertId,alertType,pageNumber)
{
	  if(confirm('Do you want to delete this Alert.'))
	  {
	  	xmlHttpAlertDelete=GetXmlHttpObject()
	  	url="alertdelete.php"
	  	if (xmlHttpAlertDelete==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	}
  	 
	  	xmlHttpAlertDelete.onreadystatechange=alertDeleted;
	  	xmlHttpAlertDelete.open("POST",url,true);
	  	xmlHttpAlertDelete.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
	  	var post_var;
	  	if(alertType=="system_alert")
	  		post_var='delete_system_alert_x=11&message_alert_id=' + alertId  + '&PageNumber=' + pageNumber +'&page=myaroxo';
	 	if(alertType=="alert")
	  		post_var='delete_alert_x=11&message_alert_id=' + alertId  + '&PageNumber=' + pageNumber +'&page=myaroxo';
	
      	xmlHttpAlertDelete.send(post_var);
	  }
}

function alertDeleted() 
{ 

	if (xmlHttpAlertDelete.readyState==4)
	{ 
		var result = xmlHttpAlertDelete.responseText;	
		var result =trim(result);
		
		if(result!="No alert found")
		{
			
			document.getElementById("aroxo_alert").innerHTML=result;
			isPagingNeedForAlert();
			document.getElementById("alert_message").style.display="block";
			//setTimeout ( " hideAlert()", 1500 );
		}
		else
		{
			document.getElementById("tbl_aroxo_alert").style.display="none";
			//document.getElementById("tr_aroxo_alert2").style.display="none";
		}
	}
}
function isPagingNeedForAlert()
{
		xmlHttpAlertPaging=GetXmlHttpObject()
	  	url="alertdelete.php"
	  	if (xmlHttpAlertPaging==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	}
		xmlHttpAlertPaging.onreadystatechange=pagingHandler;
	  	xmlHttpAlertPaging.open("POST",url,true);
	  	xmlHttpAlertPaging.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
	  	var post_var;
 		post_var='check_for_paging=1';
      	xmlHttpAlertPaging.send(post_var);
}
function pagingHandler()
{
	if (xmlHttpAlertPaging.readyState==4)
	{ 
		var result = xmlHttpAlertPaging.responseText;	
		var result =trim(result);
		if(result!="")
		{
			
			if(result==1)
			{
				document.getElementById("alert_paging").style.display="block";
			}
			else if(result==2)
			{
				//document.getElementById("alert_div").style.display="none";
			}
			
			

			
			
		}
	}
}
function hideAlert()
{
	document.getElementById("alert_message").style.display="none";
}





function deleteAlertX(alertId,alertType,pageNumber)
{
	  if(confirm('Do you want to delete this Alert.'))
	  {
	  	xmlHttpAlertDeleteX=GetXmlHttpObject()
	  	url="alertdelete.php"
	  	if (xmlHttpAlertDeleteX==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	}
  	 
	  	xmlHttpAlertDeleteX.onreadystatechange=alertDeletedX;
	  	xmlHttpAlertDeleteX.open("POST",url,true);
	  	xmlHttpAlertDeleteX.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
	  	var post_var;
	  	if(alertType=="system_alert")
	  		post_var='delete_system_alert_x=11&message_alert_id=' + alertId + '&PageNumber=' + pageNumber +'&page=aroxoalert' ;
	 	if(alertType=="alert")
	  		post_var='delete_alert_x=11&message_alert_id=' + alertId + '&PageNumber=' + pageNumber +'&page=aroxoalert';
	
      	xmlHttpAlertDeleteX.send(post_var);
	  }
}
function alertDeletedX() 
{ 
	if (xmlHttpAlertDeleteX.readyState==4)
	{ 
	
		var resultX = xmlHttpAlertDeleteX.responseText;	
		var resultX =trim(resultX);
		
		
		if(resultX!="")
		{
			
			document.getElementById("aroxo_alert").innerHTML=resultX;
			findPageSize();
			
			//setTimeout ( " hideAlert()", 1500 );
		}
	}
}
function findPageSize()
{
		xmlHttpAlertPage=GetXmlHttpObject()
	  	url="alertdelete.php"
	  	if (xmlHttpAlertPage==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	}
		xmlHttpAlertPage.onreadystatechange=pageHandler;
	  	xmlHttpAlertPage.open("POST",url,true);
	  	xmlHttpAlertPage.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
	  	var post_var;
		var pageNumber=document.getElementById("PageNumber").value;
 		post_var="check_for_page=1&PageNumber=" + pageNumber;
      	xmlHttpAlertPage.send(post_var);
}

function pageHandler()
{
	if (xmlHttpAlertPage.readyState==4)
	{ 
	 
		var result = xmlHttpAlertPage.responseText;	
		var result =trim(result);
		if(result!="")
		{
			document.getElementById("page_combo").innerHTML=result;
		}
	}
}

/* ---- For deleting alert using ajax -Code by Mujifur -----*/
/* ----                Ending here                     -----*/



function fmbExpandSearchLink(){
	document.getElementById("expand").value='yes';
	for(i=0;i<(arguments.length);i++){
			
			if(document.getElementById(arguments[i]).value!=0){
			//	alert(document.getElementById(arguments[i]).value);
				document.getElementById(arguments[i]).value=0;
				break;
			}
		
	}
	document.getElementById("findbuyers").submit();
	
}


function fmbSimilarSearchLink(){
	document.getElementById("expand").value='yes';
	for(i=0;i<(arguments.length);i++){
			
		//	if(document.getElementById(arguments[i]).value!=0){
			//	alert(document.getElementById(arguments[i]).value);
				document.getElementById(arguments[i]).value=0;
		//		break;
		//	}
		
	}
	document.getElementById("findbuyers").submit();
	
}


function fmbLowPriceLink(){
	//alert(document.getElementById('low'));
	document.getElementById('low').value='yes';
	document.findbuyers.submit();
}
	
	function searchResetChilds(grandParent){
	var flag;
	//alert(grandParent);
		
		for(i=1;i<(arguments.length);i++){
			//alert(document.getElementById(arguments[i]).name);
			var count;
			var len;
			if(document.getElementById(arguments[i]).type != 'select-one'){
				flag=-1;break;
			}
			if(flag!=-1){
			flag=flag+1;
			}
			if(flag>=3){
				//alert(elements[i].options.length);
				//alert(elements[i].name);
				//elements[i].innerHTML='<option value=0 >Any / Don\'t Mind</option>';
			
			len=document.getElementById(arguments[i]).options.length;
			lent=len-1;
			//alert(len);
			//document.elements[i].options[lent].selected=true;
			//alert(document.elements[i].options[lent]);
    		for (count = 0 ;  count<len ; count++) {
				if(count!=0){
					//alert(count);
					//alert(elements[i].options);
					document.getElementById(arguments[i]).options[count]=null;// (count);
				}
    		}
			document.getElementById(arguments[i]).disabled=true;
			
				//elements[i].value = 0;
				//elements[i].text = 'Any/Dont mind';
			}
			
			if((document.getElementById(arguments[i]).type == 'select-one')&&(document.getElementById(arguments[i]).name==grandParent)){
				flag=1;
			}
			
			
		}
	
	//alert(grandParent);
}

function resetSelectMenus(){
	for(i=0;i<(arguments.length);i++){
		
		if(document.getElementById(arguments[i]).type == 'select-one'){
				document.getElementById(arguments[i]).value="";
			}
		}
		//The below setting for price dropdown
		if(document.getElementById('drpPrice') != null && typeof(document.getElementById('drpPrice')) != 'undefined' ){
			document.getElementById('drpPrice').value=0;
		}
	//document.getElementById('reset').style.display="none";
}


function searchResetFilter(){
	var flag = 0;
	for(i=0;i<(arguments.length);i++){
		//alert(arguments[i]);
		if(flag==0){
			if(document.getElementById(arguments[i]).type == 'select-one'){
				if(document.getElementById(arguments[i]).value!=""){
				flag=1;	
				}
			}
		}
	}
	if(document.getElementById('drpPrice') != null && typeof(document.getElementById('drpPrice')) != 'undefined' ){
		if(document.getElementById('drpPrice').value!=0){
			flag=1;
		}
	}
	if(flag==1){
		//document.getElementById('reset').style.display=""
	}
	else{
		//document.getElementById('reset').style.display="none";
	}
}


function negoPriceFormValidate(form){
	
	
	if(trim(form.yourPrice.value)==""){
		alert("Hmmmm. You've not set a price for your negotiation! I'm not sure they'll sell it to you for free!");
		form.yourPrice.focus();
		return false;
	}

	if(isNaN(form.yourPrice.value)){
		alert("Strange. There seems to be something odd wrong with your price? Could you take another look to see if there's a letter in there?");
		form.yourPrice.focus();
		return false;
	}
	
	var negoPrice = eval(form.yourPrice.value);
	if(negoPrice==0){
		alert("Hmmmm. You've not set a price for your negotiation! I'm not sure they'll sell it to you for free!");
		form.yourPrice.focus();
		return false;
	}
	

	/*if(form.negoExpire.selectedIndex==0){
		alert("Please select expiry date!");
		form.negoExpire.focus();
		return false;
	}*/
	
		
	return true;
}

function negoAddressFormValidate(form){
	if(trim($F('first_name'))==""){
		alert("Ooops. You've not given a firstname!");
		$('first_name').focus();
		return false;		
	}
	
	/*if(trim($F('sur_name'))==""){
		alert("Ooops. You've not given a surname!");
		$('sur_name').focus();
		return false;		
	}*/
	
	if(!validFirstname($F('first_name'))){
		alert("Invalid First Name");
		$('first_name').focus();
		return false;		
	}
	if(trim($F('address1'))=="" && trim($F('address2'))=="" && trim($F('address3'))==""){
		alert("Please enter the address");
		$('address1').focus();
		return false;		
	}
	if(trim($F('city'))==""){
		alert("Please enter the city");
		$('city').focus();
		return false;		
	}
	if(!validCity_County($F('city'))){
		alert("Invalid city name");
		$('city').focus();
		return false;		
	}
	if(trim($F('zip_code'))==""){
		alert("Please enter the postal code");
		$('zip_code').focus();
		return false;		
	}
	if(IsAlphaNumeric($F('zip_code'))){
		alert("Invalid postal code");
		$('zip_code').focus();
		return false;		
	}
	if(trim($F('country')) == 0 ){
		alert("Please select the country");
		$('country').focus();
		return false;		
	}
	return true;
	
}


function setPaymentTextEnable(id){
	textareaId="gateWayDescription["+id+"]";
	tableId="pay_opt_table_"+id;
	hiddenId="gatwayname["+id+"]";
	if(document.getElementById(textareaId).disabled){
		document.getElementById(textareaId).disabled=false;
		document.getElementById(tableId).className="pay_opt_en_border";
		document.getElementById(hiddenId).value=id;
	}	
	else{
		document.getElementById(textareaId).disabled=true;	
		document.getElementById(tableId).className="pay_opt_dis_border";
		document.getElementById(hiddenId).value="";
	}	
}

function isValidDOB(theElement,focuselement)
{
	// dd-mmm-yyyy format; leading zeros required
	str = theElement.value;
	len = str.length;
	if(len>0)
	{
		
		if(len != 10)
		{
			alert("Ooops, you've missed out your date of birth");
			focuselement.focus();
			return false;
		}
		strday = str.substring(0, 2);
		strmonth = str.substring(3, 5).toUpperCase();
		stryear = str.substring(6, 10);
		if( isNaN(strday) || (strday < 0) || isNaN(stryear) || (stryear < 0))
		{
			alert("Ooops, you've missed out your date of birth");
			focuselement.focus();
			return false;
		}
		// Ensure valid month and set maximum days for that month...
		// I wonder if this is Y3K compliant ;-)
		if( (strmonth == "01") || (strmonth == "03") || (strmonth == "05") || (strmonth == "07") || (strmonth == "08") || (strmonth == "10") || (strmonth == "12") )
		{
			monthdays = 31
		}
		else if( (strmonth == "04") || (strmonth == "06") || (strmonth == "09") || (strmonth == "11") )
		{
			monthdays = 30
		}
		else if(strmonth == "02")
		{
			monthdays = ((stryear % 4) == 0) ? 29 : 28;
		}
		else
		{
			alert("Ooops, you've missed out your date of birth");
			focuselement.focus();
			return false;
		}
		if(strday > monthdays)
		{
			alert("Ooops, you've missed out your date of birth");
			focuselement.focus();
			return false;
		}
	}
	return true;
}

function isValidDBDateInEdit(theElement,focuselement)
{
	// dd-mmm-yyyy format; leading zeros required
	str = theElement.value;
	len = str.length;
	if(len>0)
	{
		
		if(len != 10)
		{
			alert("Oops. There seems to be something wrong with your date of birth, can you have another look?");
			focuselement.focus();
			return false;
		}
		strday = str.substring(0, 2);
		strmonth = str.substring(3, 5).toUpperCase();
		stryear = str.substring(6, 10);
		if( isNaN(strday) || (strday < 0) || isNaN(stryear) || (stryear < 0))
		{
			alert("Oops. There seems to be something wrong with your date of birth, can you have another look?");
			focuselement.focus();
			return false;
		}
		// Ensure valid month and set maximum days for that month...
		// I wonder if this is Y3K compliant ;-)
		if( (strmonth == "01") || (strmonth == "03") || (strmonth == "05") || (strmonth == "07") || (strmonth == "08") || (strmonth == "10") || (strmonth == "12") )
		{
			monthdays = 31
		}
		else if( (strmonth == "04") || (strmonth == "06") || (strmonth == "09") || (strmonth == "11") )
		{
			monthdays = 30
		}
		else if(strmonth == "02")
		{
			monthdays = ((stryear % 4) == 0) ? 29 : 28;
		}
		else
		{
			alert("Please select / enter a valid Date. (DD-MMM-YYYY)");
			focuselement.focus();
			return false;
		}
		if(strday > monthdays)
		{
			alert("Please select / enter a valid Date. (DD-MMM-YYYY)");
			focuselement.focus();
			return false;
		}
	}
	return true;
}

function isDate(theElement,focuselement)
{
	// dd-mmm-yyyy format; leading zeros required
	str = theElement.value;
	len = str.length;
	if(len>0)
	{
		
		if(len != 10)
		{
			alert("Please select / enter a valid Date. (DD-MMM-YYYY)");
			focuselement.focus();
			return false;
		}
		strday = str.substring(0, 2);
		strmonth = str.substring(3, 5).toUpperCase();
		stryear = str.substring(6, 10);
		if( isNaN(strday) || (strday < 0) || isNaN(stryear) || (stryear < 0))
		{
			alert("Please select / enter a valid Date. (DD-MMM-YYYY)");
			focuselement.focus();
			return false;
		}
		// Ensure valid month and set maximum days for that month...
		// I wonder if this is Y3K compliant ;-)
		if( (strmonth == "01") || (strmonth == "03") || (strmonth == "05") || (strmonth == "07") || (strmonth == "08") || (strmonth == "10") || (strmonth == "12") )
		{
			monthdays = 31
		}
		else if( (strmonth == "04") || (strmonth == "06") || (strmonth == "09") || (strmonth == "11") )
		{
			monthdays = 30
		}
		else if(strmonth == "02")
		{
			monthdays = ((stryear % 4) == 0) ? 29 : 28;
		}
		else
		{
			alert("Please select / enter a valid Date. (DD-MMM-YYYY)");
			focuselement.focus();
			return false;
		}
		if(strday > monthdays)
		{
			alert("Please select / enter a valid Date. (DD-MMM-YYYY)");
			focuselement.focus();
			return false;
		}
	}
	return true;
}
					
					function validateDate(dd,mm,yyyy,frm_date){
					document.getElementById(frm_date).value = document.getElementById(dd).value+"/"+document.getElementById(mm).value+"/"+document.getElementById(yyyy).value;
						if(!isDate(document.getElementById(frm_date),document.getElementById(dd)))
						{
							return false;
						}
					}
					function onlydate()
				   	{
						var key=event.keyCode;
						//alert(key);
						if(!((key>=48 && key<=59) ||  (key>=97 && key<=122) || (key>=65 && key<=90) || key==47 || key==45 ))//47,45,
						{
							event.keyCode=0;
						}
				   	}
					
					function stockDelete(stock_id){
					xmlHttp5=GetXmlHttpObject();
					if (xmlHttp5==null)
					  {
					  alert ("Your browser does not support AJAX!");
					  return;
					  } 
					var url="checkstockdelete.php?stock_id="+stock_id;
					xmlHttp5.onreadystatechange=stockDeleteSuccess;
					xmlHttp5.open("GET",url,true);
					xmlHttp5.send(null);
					} 
				
					function stockDeleteSuccess() 
					{ 
						if (xmlHttp5.readyState==4)
						{ 
							var result = xmlHttp5.responseText;
							if(trim(result) != ''){
								document.getElementById("stock_delete").value=1;
								if(confirm("Are you sure to delete the Stock Item?")){
									document.getElementById("frmViewStock").action="index.php?pgtp=myaroxo";
									document.getElementById("frmViewStock").submit();
								}
							}else{
								alert("You cannot delete this Stock Item until you have completed or retracted the accepted offer(s) for this item. \n If you believe you have, then it is possible that the buyer has not yet completed the item.");
								document.getElementById("frmViewStock").submit=false;
							}
						}
					}
					
					
	function createAlert(stkForm){
		var form_element="document."+stkForm+".alertForm.value=1";
		eval(form_element);
		var form_submit="document."+stkForm+".method='post'";
		eval(form_submit);
		var form_submit="document."+stkForm+".pgtp.value='stockalert'";
		eval(form_submit);
		var form_submit="document."+stkForm+".submit()";
		eval(form_submit);
	}
	function createAlertStkAll(stkForm){
		var form_element="document."+stkForm+".alertForm.value=1";
		eval(form_element);
		var form_submit="document."+stkForm+".action='index.php?pgtp=stockalert'";
		eval(form_submit);
		var form_submit="document."+stkForm+".submit()";
		eval(form_submit);
	}
	
	function uploadImage(form,action){
	document.getElementById(form).action=action;
	document.getElementById(form).target='upload_frame';
	document.getElementById(form).submit();
	}
	
	
	function validateQuickJump(){
		//var form_element = document.getElementById('transaction_id').value;
		if($F('transaction_id')==""){
		alert("Please enter the transaction id");
		$('transaction_id').focus();
		return false;		
		}
		else{
			//substr(4,8)
			var trans_id = trim($F('transaction_id'));
			var first_char = trans_id.substr(0,1)
			if(first_char=='#'){
				trans_id=trans_id.substr(1,trans_id.length)
			}
			if(!checkValid(trans_id,'1234567890')) { 
			alert("Transaction id should be number.");
			$('transaction_id').focus();
			return false;
			}
			return true;
		}
		
	}
	
	function chargeAccountdisplay(varChargeUpAmount){
		rad_yes=document.getElementById("future_yes");
		rad_no=document.getElementById("future_no");
		browser=navigator.appName;
		if(browser=="Microsoft Internet Explorer"){ 
			view="inline";
		}
		else{
			view="table-row";
		}
		if(rad_yes.checked){
			
			
			
			if(document.getElementById("chargeUp")!=null){
				document.getElementById("chargeUp").style.display="none";
			}
			if(document.getElementById("addAutoPurchase")!=null){
				document.getElementById("addAutoPurchase").style.display="inline";
			}
			if(document.getElementById("editAutoPurchase")!=null){
				document.getElementById("editAutoPurchase").style.display="inline";
			}
			if(document.getElementById("cancelAutoPurchase")!=null){
				document.getElementById("cancelAutoPurchase").style.display="inline";
			}
			
			if(varChargeUpAmount!=undefined){
				document.getElementById("amount").value=varChargeUpAmount;
			}
			document.getElementById("topup_tr").style.display="none";
			//document.getElementById("auto_purchase_text_tr").style.display=view;
			//document.getElementById("auto_purchase_tr").style.display=view;
			document.getElementById("limit_tr").style.display=view;
			document.getElementById("max_amount_tr").style.display=view;
		}
		else if(rad_no.checked){
			
			
			if(document.getElementById("chargeUp")!=null){
				document.getElementById("chargeUp").style.display="inline";
			}
			if(document.getElementById("addAutoPurchase")!=null){
				document.getElementById("addAutoPurchase").style.display="none";
			}
			if(document.getElementById("editAutoPurchase")!=null){
				document.getElementById("editAutoPurchase").style.display="none";
			}
			if(document.getElementById("cancelAutoPurchase")!=null){
				document.getElementById("cancelAutoPurchase").style.display="none";
			}
			
			//document.getElementById("amount").value="";
			document.getElementById("topup_tr").style.display=view;
			//document.getElementById("auto_purchase_text_tr").style.display="none";
			//document.getElementById("auto_purchase_tr").style.display="none";
			document.getElementById("limit_tr").style.display="none";
			document.getElementById("max_amount_tr").style.display="none";	
		}
	}
	
	
	function chargeUpValidate(){
  varAmount=document.getElementById("amount");
  if((varAmount.value=="")||(isNaN(varAmount.value)) )
  {    
   alert("Please Enter the valid amount");
   varAmount.focus();
   return false;
  }
  if(varAmount.value<10){
   alert("Sorry, the minimum top-up amount Aroxo accepts is £10.00");
   varAmount.focus();
   return false;
  }
  return true;
    
 }
 
 function AutoPurchaseValidate(){
  varAmount=document.getElementById("amount");
  
  //varAutopurchase=document.getElementById("autopurchase");
  //varAutopurchaseOption=varAutopurchase.options[varAutopurchase.selectedIndex];
  
  varInterval=document.getElementById("interval");
  varIntervalOption=varInterval.options[varInterval.selectedIndex];
  
  varMaxAmount=document.getElementById("maxAmount");
  varMaxAmountOption=varMaxAmount.options[varMaxAmount.selectedIndex];
  
  if((varAmount.value=="")||(isNaN(varAmount.value)) )
  {    
   alert("Please Enter the valid amountxxxxx.");
   varAmount.focus();
   return false;
  }
  
  if(varAmount.value<10){
   alert("Sorry, the minimum top-up amount Aroxo accepts is £10.00");
   varAmount.focus();
   return false;
  }
  /*if(varAutopurchaseOption.value==0){
   alert("Please Select Auto-purchase at.");
   varAutopurchase.focus();
   return false;
  }*/
  /*if(varIntervalOption.value==0){
   alert("Please Select Re-charge Limit.");
   varInterval.focus();
   return false;
  }*/
  /*if(varMaxAmountOption.value==0){
   alert("Please Maximum amount.");
   varMaxAmount.focus();
   return false;
  }*/
  /*if( (eval(varMaxAmountOption.value)!=0) && (eval(varMaxAmountOption.value) < eval(varAmount.value)) )
  {
   alert("Maximum amount should be greater than or equal to top-up amount.");
   varMaxAmount.focus();
   return false;
  }*/
  
   return true;
 }
	function editAutoPurchaseText(tag){
		val=tag.options[tag.selectedIndex].value;
		document.getElementById("autoPurchaseText").innerHTML=val;
		
	}
	
	function checkNotes(){
		
		if (trim($F("note")) == "Sellers see these notes before they send you offers, so if you've got any special requirements stick them here."){
			$("note").value='';
			$("note").style.color="#000000";
			//$("note").focus();
		}
		return false;
	}
	function setNotes(){
		if (trim($F("note")) == ""){
			$("note").style.color="#888888";
			$("note").value="Sellers see these notes before they send you offers, so if you've got any special requirements stick them here.";
		}
	}
	
	function checkStkNotes(){
			
		if (trim($F("note")) == "Include here any difference from Aroxo's product description, and anything else you want to say about your item."){
			$("note").style.color="#000000";
			$("note").value='';
		}
	}
	function setStkNotes(){
		if (trim($F("note")) == ""){
			$("note").style.color="#888888";
			$("note").value="Include here any difference from Aroxo's product description, and anything else you want to say about your item.";
		}
	}
	
	
	//salespayterms.tpl
	function checkPayDescription(){
		if (trim($F("payTemp_description")) == "Remember to include your contact details and returns policy here."){
			$("payTemp_description").style.color="#000000";
			$("payTemp_description").value='';
		}
	}
	//salespayterms.tpl
	function setPayDescription(){
		if (trim($F("payTemp_description")) == ""){
			$("payTemp_description").style.color="#888888";
			$("payTemp_description").value="Remember to include your contact details and returns policy here.";
		}
	}
	
	//salespayterms.tpl
	function checkPostageDescription(){
		if (trim($F("postage_descriptionAdd")) == "e.g. First Class"){
			$("postage_descriptionAdd").style.color="#000000";
			$("postage_descriptionAdd").value='';
		}
	}
	//salespayterms.tpl
	function setPostageDescription(){
		if (trim($F("postage_descriptionAdd")) == ""){
			$("postage_descriptionAdd").style.color="#888888";
			$("postage_descriptionAdd").value="e.g. First Class";
		}
	}
	
	
	function notPaid(){
		contForm=document.getElementById("frmwantedTop");
		inField=document.createElement("input");
		inField.type="hidden";
		inField.name="select_payment_x";
		inField.id="select_payment";
		inField.value="1";
		contForm.appendChild(inField);
		contForm.action="index.php?pgtp=accepted";
		contForm.submit();
	}
	 
	function stockIsEmpty(){
		alert("You don't have any of these in stock, Please update your stock level to accept or counter offer.");
		return false;	
	}
	
	function doChargeUp(){
		//document.frmOffer.action="index.php?pgtp=chargeaccount";
		document.frmOffer.action="index.php?pgtp=googlechargeaccount";
		document.frmOffer.method="post";		
		document.frmOffer.submit();
	}

	function changeExpiresOn(varDivId,varDisplaymode){
		//alert(varFrequencyId);
		if(varDisplaymode=='1') {
					
			document.getElementById(varDivId).style.visibility = "visible";
			document.getElementById(varDivId).style.display = "inline";
		} 
		else {
			document.getElementById(varDivId).style.visibility = "hidden";	
			document.getElementById(varDivId).style.display = "none";
		}

	}
	
	
	function updateExpreDate(tag){
		
		var varForm=tag;
		
	
		
		varExpiryDays=varForm.expiryDays.options[varForm.expiryDays.selectedIndex].value;
		
		
		
		varTemplatedId=varForm.templateID.value;
		
		varWantedId=varForm.wantedAd.value;
		
		
		
		postVar="";
		
		postVar ="templateId="+varTemplatedId;
		
		postVar +="&wantedId="+varWantedId;
		
		postVar +="&expDate="+varExpiryDays;
		
		postVar +="&extendeWantedad=true";
	
		
		xmlHttpChkAvail=GetXmlHttpObject();
		if (xmlHttpChkAvail==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url="extendwantedad.php";
		xmlHttpChkAvail.onreadystatechange=doUpdateExpreDate;
		xmlHttpChkAvail.open("POST",url,true);
		xmlHttpChkAvail.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		xmlHttpChkAvail.send(postVar);
		changeExpiresOn('renew_win_block',0);
	
	}

	function doUpdateExpreDate(){
		if (xmlHttpChkAvail.readyState==4){ 
			var result 	= xmlHttpChkAvail.responseText;	
			
			if(result &&  trim(result)!=""){
				document.getElementById("expire_on").innerHTML=result;
			}
			else{
				alert("Your session out!");	
				window.location.reload(true);
			}
			
		}
	}
	
	//The below 2 functions are moved to search_aroxo.js by Karthikeyan R on 03-N0v-09
	//================================================================================
	/*
	function removeSearchText(tag){
		if(tag.value=="Search Aroxo"){
			tag.value="";
		}
		//document.getElementById("txtSearchBox").className="roundboxdiv_selected";
		document.getElementById("txtSearch").className="roundbox";
	}
	function insertSearchText(tag){
		if(tag.value==""){
			tag.value="Search Aroxo";
			document.getElementById("txtSearch").className="roundbox_grey";
		}
		//document.getElementById("txtSearchBox").className="roundboxdiv";
	}
	*/
	
	 function show_loading(field,flag){
		

		block=trim(field)+"_block";
		gif=trim(field)+"_gif";
		td_block=trim(field)+"_td";
		
		
		
		
			
		if(flag){
			document.getElementById(td_block).className="bgblure";
		
		}
		else{
			document.getElementById(td_block).className="tdbox_l";
			
		}
		
	} 
	function updateStock(stock_id,field){
		
		id="";
		
		if(field=="price"){
			id="minimum_sell_price";
		}
		if(field=="description"){
			id="note";
		}
		if(field=="stock"){
			id="stock_available";
			id2="stock_unlimited";
		}
		
		show_loading(field,true);	
	
		if(field=="stock"){
			var_stock_value=document.getElementById(id).value;
			is_unlimited=document.getElementById(id2).checked;
			
			if(is_unlimited){
				field_value=-1;
			}
			else if(var_stock_value!=""){
				field_value=var_stock_value;
			}
			else{
				show_loading(field,false);
				alert("Please enter how many items you have in stock");
				
				return false;
			}

		}
		else{
			field_value=document.getElementById(id).value;
		}
		
		postVar="";
		
		postVar ="stock_id="+stock_id;
		
		postVar +="&field="+field;
		
		postVar +="&field_value="+field_value;
	
		
		xmlHttpChkAvail=GetXmlHttpObject();
		if (xmlHttpChkAvail==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url="stockupdateajax.php";
		xmlHttpChkAvail.onreadystatechange=doUpdateStock;
		xmlHttpChkAvail.open("POST",url,true);
		xmlHttpChkAvail.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		xmlHttpChkAvail.send(postVar);
		
	
	}

	function doUpdateStock(){
		if (xmlHttpChkAvail.readyState==4){ 
			var result 	= xmlHttpChkAvail.responseText;	
			
			if(result &&  trim(result)!=""){
				show_loading(result,false);
				alert("Modified successfully!");
				//document.getElementById("expire_on").innerHTML=result;
			}
			else{
				alert("Your session out!");	
				window.location.reload(true);
			}
			
		}
	}
	
	
	
	function validate_and_invite(keyvalue)
	{	
	
		if(keyvalue==13)
		{
		if(document.getElementById("news_subscripe_email").value=="")
		{
			alert("Please enter your email");
			document.getElementById("news_subscripe_email").focus();
			return false;
		}
		
		result=isEmailAddr(document.getElementById("news_subscripe_email").value);
		if(result!=true)
		{
		alert("Oops, that doesn't look like an email address to us!");
		document.getElementById("news_subscripe_email").focus();
			return false;
		}
		else
			return true;
		}
	}
	
	function isEmailAddr(email)
	{
		var result = false;
		var theStr = new String(email);
		var index = theStr.indexOf("@");
		if (index > 0)
		{
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
		}
		return result;
	}
	
	// Added By Murugan to show popup box with greybg

	function showpopupbox_withoverlay(showdiv,bgoverlaycolor,tw,th)
	{
	
	var wheight=getfullscreen_height();
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id","greybgdiv");
	document.body.appendChild(newdiv);
	
	document.getElementById('greybgdiv').style.zIndex=5;
	document.getElementById('greybgdiv').style.position="absolute";
	if(bgoverlaycolor=="white" || bgoverlaycolor=="")
	document.getElementById('greybgdiv').style.background="url(images/whitebg_trans.png) repeat";
	if(navigator.appName=="Microsoft Internet Explorer")
	document.getElementById('greybgdiv').style.marginTop=-(wheight)+"px";
	
	curvebox(showdiv,tw,th);
	
	document.getElementById('greybgdiv').style.width=(screen.width-27)+"px";
	document.getElementById('greybgdiv').style.height=wheight+"px";
	document.getElementById('greybgdiv').style.display='block';
	document.getElementById(showdiv).style.display='block';
	}
	
	function curvebox(showdiv,tw,th)
	{
	var leftcorner=document.createElement("div");
		leftcorner.setAttribute("id", "lefttopcornerdiv");
		leftcorner.style.cssFloat = "left";
		leftcorner.style.styleFloat = "left";
		leftcorner.style.backgroundImage="url('"+document.getElementById("ARX_SiteURL_txt").value+"images/left_top_corner_trans.png')";	
		leftcorner.style.backgroundRepeat="no-repeat";
		leftcorner.style.width=25+"px";
		leftcorner.style.height=29+"px";
		leftcorner.style.display="inline";
		leftcorner.style.zIndex=1;
		leftcorner.style.position="absolute";
		leftcorner.style.top=-1+"px";
		leftcorner.style.left=-2+"px";
		document.getElementById(showdiv).appendChild(leftcorner);
		
		var topborderdiv=document.createElement("div");
		topborderdiv.setAttribute("id", "topborder_div");
		topborderdiv.style.width = tw+"px";	
		topborderdiv.style.height = 10+"px";		
		topborderdiv.style.backgroundImage="url('"+document.getElementById("ARX_SiteURL_txt").value+"images/top_middle.gif')";	
		topborderdiv.style.backgroundRepeat="repeat-x";
		topborderdiv.style.display="inline";
		topborderdiv.style.zIndex=1;
		topborderdiv.style.position="absolute";
		topborderdiv.style.left=15+"px";
		topborderdiv.style.top=-1+"px";
		document.getElementById(showdiv).appendChild(topborderdiv);
		
		var leftbt_corner=document.createElement("div");
		leftbt_corner.setAttribute("id", "leftbottomcornerdiv");
		leftbt_corner.style.cssFloat = "left";
		leftbt_corner.style.styleFloat = "left";
		leftbt_corner.style.backgroundImage="url('"+document.getElementById("ARX_SiteURL_txt").value+"images/left_bottom_corner_trans.png')";	
		leftbt_corner.style.backgroundRepeat="no-repeat";
		leftbt_corner.style.width=25+"px";
		leftbt_corner.style.height=29+"px";
		leftbt_corner.style.display="inline";
		leftbt_corner.style.zIndex=1;
		leftbt_corner.style.position="absolute";
		leftbt_corner.style.bottom=-11+"px";
		leftbt_corner.style.left=-2+"px";
		document.getElementById(showdiv).appendChild(leftbt_corner);
		
		var leftborderdiv=document.createElement("div");
		leftborderdiv.setAttribute("id", "leftborder_div");
		leftborderdiv.style.width = 5+"px";	
		leftborderdiv.style.height = (th)+"px";		
		leftborderdiv.style.backgroundImage="url('"+document.getElementById("ARX_SiteURL_txt").value+"images/left_middle.gif')";	
		leftborderdiv.style.backgroundRepeat="repeat-y";
		leftborderdiv.style.display="inline";
		leftborderdiv.style.zIndex=1;
		leftborderdiv.style.position="absolute";
		leftborderdiv.style.left=-1+"px";
		leftborderdiv.style.top=18+"px";	
		leftborderdiv.style.bottom=10+"px";	
		document.getElementById(showdiv).appendChild(leftborderdiv);
	
		var right_corner=document.createElement("div");
		right_corner.setAttribute("id", "righttopcornerdiv");
		right_corner.style.cssFloat = "right";
		right_corner.style.styleFloat = "right";
		right_corner.style.backgroundImage="url('"+document.getElementById("ARX_SiteURL_txt").value+"images/top_right_corner_trans.png')";	
		right_corner.style.backgroundRepeat="no-repeat";
		right_corner.style.width=25+"px";
		right_corner.style.height=29+"px";
		right_corner.style.display="inline";
		right_corner.style.zIndex=1;
		right_corner.style.position="absolute";
		right_corner.style.top=-2+"px";
		right_corner.style.right=-7+"px";
		document.getElementById(showdiv).appendChild(right_corner);
		
		
		var rightborderdiv=document.createElement("div");
		rightborderdiv.setAttribute("id", "righborder_div");
		rightborderdiv.style.width = 10+"px";	
		rightborderdiv.style.height = th+"px";		
		rightborderdiv.style.backgroundImage="url('"+document.getElementById("ARX_SiteURL_txt").value+"images/right_border.gif')";	
		rightborderdiv.style.backgroundRepeat="repeat-y";
		rightborderdiv.style.display="inline";
		rightborderdiv.style.zIndex=1;
		rightborderdiv.style.position="absolute";
		rightborderdiv.style.right=-1+"px";
		rightborderdiv.style.top=18+"px";	
		rightborderdiv.style.bottom=10+"px";	
		document.getElementById(showdiv).appendChild(rightborderdiv);
		
		var rightbottom_corner=document.createElement("div");
		rightbottom_corner.setAttribute("id", "rightbottomcornerdiv");
		rightbottom_corner.style.cssFloat = "right";
		rightbottom_corner.style.styleFloat = "right";
		rightbottom_corner.style.backgroundImage="url('"+document.getElementById("ARX_SiteURL_txt").value+"images/right_bottom_corner_trans.png')";	
		rightbottom_corner.style.backgroundRepeat="no-repeat";
		rightbottom_corner.style.width=25+"px";
		rightbottom_corner.style.height=29+"px";
		rightbottom_corner.style.display="inline";
		rightbottom_corner.style.zIndex=1;
		rightbottom_corner.style.position="absolute";
		rightbottom_corner.style.bottom=-11+"px";
		rightbottom_corner.style.right=-7+"px";
		document.getElementById(showdiv).appendChild(rightbottom_corner);
		
		var bottomborderdiv=document.createElement("div");
		bottomborderdiv.setAttribute("id", "bottomborder_div");
		bottomborderdiv.style.width = tw+"px";	
		bottomborderdiv.style.height = 10+"px";		
		bottomborderdiv.style.backgroundImage="url('"+document.getElementById("ARX_SiteURL_txt").value+"images/bottom_middle.gif')";	
		bottomborderdiv.style.backgroundRepeat="repeat-x";
		bottomborderdiv.style.display="inline";
		bottomborderdiv.style.zIndex=1;
		bottomborderdiv.style.position="absolute";
		bottomborderdiv.style.left=15+"px";
		bottomborderdiv.style.bottom=-1+"px";
		document.getElementById(showdiv).appendChild(bottomborderdiv);
	}
	
	function closepopupbox_withoverlay(closediv)
	{
	document.getElementById('greybgdiv').style.display='none';
	document.getElementById(closediv).style.display='none';
	}
	
	
	function getfullscreen_height(){	
		
		if(navigator.appName=="Microsoft Internet Explorer" || navigator.appName=="Opera")	
		{	
		var totheight=screen.height + document.body.scrollHeight;
		if(navigator.appName=="Opera")	return totheight-420;
		else return totheight;
		}
		else	
		{
		var d= document.documentElement;
		var b= document.body;
		var who= d.offsetHeight? d: b ;
		//alert(who.scrollHeight+" "+who.offsetHeight);
		return Math.max(who.scrollHeight,who.offsetHeight);
		}
	}
	
	function reloadCapcha(divId)
	{
		if(divId == 'aroxoImgCapcha')
			document.getElementById('human_error_msg').innerHTML = '';
		/*else if(divId == 'aroxoContactImgCapcha')
			document.getElementById('error_box').style.display = 'none';*/
		
		document.getElementById('humanVerifyCode').value = '';
		document.getElementById('humanVerifyCode').focus();
		document.getElementById(divId).innerHTML = '<p style="color:#ff0000; height:30px;">Loading...</p>';
		setTimeout ( "loadCapchaImg('"+divId+"')", 1000 );
	
	}
	function loadCapchaImg(divId)
	{
		ajaxrequest("ajaxLoadCapcha.php","display",document.getElementById(divId),0)		
	}
	function display(txt,obj){
		//alert(txt)
		obj.innerHTML = txt;
	}
	function echeck(str,divid) {
		var errEmail = "<p class='error'>Invalid email address</p>";
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   document.getElementById(divid).innerHTML = errEmail;
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   document.getElementById(divid).innerHTML = errEmail;
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    document.getElementById(divid).innerHTML = errEmail;
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    document.getElementById(divid).innerHTML = errEmail;
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    document.getElementById(divid).innerHTML = errEmail;
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    document.getElementById(divid).innerHTML = errEmail;
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    document.getElementById(divid).innerHTML = errEmail;
		    return false
		 }

 		 return true					
	}
	
	function validateAutoOffer(frm){
	
		
	
		/* varCountryId=document.getElementById('country');
		varCountry=frm.country;
		varChecked=false;
		for(i=0;i<varCountry.length;i++){
			
			if(varCountry[i].checked){
				varChecked=true;
				break;
			}
			
		}
		
		if(!varChecked){
			alert("Please select the country");
			varCountryId.focus();
			return false;
		}*/
		
		
		varTemplate=document.getElementById('payment_template_id');
		
		
		if(varTemplate.value==0){
			alert("You need to select which payment terms we should send with your offers");
			varTemplate.focus();
			return false;
		}

		
		return true;
	}
	
	function select_countries(frm){
		
	
	
		varStatus=false;
		if(document.getElementById("select_counrty").checked){
			varStatus=true;
		}
		
	
		varCountry=frm.country;
		for(i=0;i<varCountry.length;i++){
			
			varCountry[i].checked=varStatus;
			
			
		}
	}
	
	/* Common Ajax popup box */
var alertBox;
	function Common_AlertBox(title,msg,firstbtn,secondbtn,wid,hyt){
						
		head=title;
				//alert(Focuson_TXTname);
			if(document.getElementById(Focuson_TXTname))
			document.getElementById(Focuson_TXTname).disabled=true;
			
						alertBox = new DOMAlert(
						{
						title:head,
						text: msg,
						skin: 'aroxo',
						width: wid,
						height: hyt,
						ok: {value: true, text: firstbtn, onclick:result_AlertBox},
						cancel: {value: false, text: secondbtn, onclick:result_AlertBox}
						});
						alertBox.show();
						
				 };


	function result_AlertBox()
	{	
		curObj=result_AlertBox.arguments[0];	
		
		if(document.getElementById(Focuson_TXTname))
		{
		document.getElementById(Focuson_TXTname).disabled=false;
		document.getElementById(Focuson_TXTname).focus();
		}
		curObj.close();		
	
		retval=result_AlertBox.arguments[1];		
		// It will return false
		return retval;
	}		

//

// Functions added by Murugan for Quick Registration page validation

var uname_err=0;

function validate_quickregister()
{
resusernamecheck=check_Username('regusername');

/*	if(resusernamecheck==false)
	return false;	*/	
	
res_passcheck=check_regPassword();
/*if(res_passcheck==false)
return false;	*/

res_emailcheck=check_regEmail();
/*if(res_emailcheck==false)
return false;	*/
		
res_citycheck=check_regCity();
/*if(res_citycheck==false)
return false;	*/	

	
	if(document.getElementById("acceptTerms").checked==false){
	document.getElementById("regtc_err").innerHTML="Please confirm you accept our terms and conditions";	
	document.getElementById("regtc_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/unavailable.png";				
		return false;
	}

if(resusernamecheck==false || res_passcheck==false || res_emailcheck==false || res_citycheck==false || document.getElementById("acceptTerms").checked==false)
return false;

selcountryObj=document.getElementById("country");
selcountryIndex = selcountryObj.selectedIndex;
document.getElementById("selected_regcountry").value=selcountryObj.options[selcountryIndex].text;
//return false;
}



function check_regTC()
{

/*if(trim(document.getElementById('reguname_err').innerHTML)=="" && trim(document.getElementById('regpass_err').innerHTML)=="" && trim(document.getElementById('regemail_err').innerHTML)=="" && trim(document.getElementById('regloc_err').innerHTML)==""){*/

	if(document.getElementById("acceptTerms").checked==false){
	document.getElementById("regtc_err").innerHTML="Please confirm you accept our terms and conditions";	
	document.getElementById("regtc_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/unavailable.png";				
			return false;	
	}
	else
	{
	document.getElementById("regtc_err").innerHTML="";
	document.getElementById("regtc_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/available.png";
	return true;
	}
	
//}	
	
}

function check_regCity()
{

/*if(trim(document.getElementById('reguname_err').innerHTML)=="" && trim(document.getElementById('regpass_err').innerHTML)=="" && trim(document.getElementById('regemail_err').innerHTML)=="" && trim(document.getElementById('regpassword').value)!="" && trim(document.getElementById('email_id').value)!="" && trim(document.getElementById('regusername').value)!=""){*/

	if(trim($F('city'))==""){	
	document.getElementById("regloc_err").innerHTML="<div style='padding-top:9px;'>Please enter city name</div>";	
	document.getElementById("regcity_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/unavailable.png";				
			return false;	
	}
	else if( !validCity_County($F('city')))
	{
	document.getElementById("regloc_err").innerHTML="City should not contain<br> any special characters!";	
	document.getElementById("regcity_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/unavailable.png";					
			return false;	
	}
	else	
	{
	document.getElementById("regloc_err").innerHTML="";	
	document.getElementById("regcity_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/available.png";	
	return true;				
	}
//}	
	
}

function check_regEmail()
{	
		
		if(trim($F('email_id'))==""){
		document.getElementById("regemail_err").innerHTML="<div style='padding-top:9px;'>Please enter your email</div>";	
		document.getElementById("regemail_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/unavailable.png";			
				return false;	
		}
		else if(!isMailId($F('email_id'))){
		document.getElementById("regemail_err").innerHTML="<div style='padding-top:9px;'>Invalid email address</div>";	
		document.getElementById("regemail_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/unavailable.png";						
				return false;	
		}
		else
		{
		document.getElementById("regemail_err").innerHTML="";	
		document.getElementById("regemail_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/available.png";	
		return true;		
		}
		
}

function check_regPassword()
{

	/*if(trim(document.getElementById('regemail_err').innerHTML)=="" && trim(document.getElementById('email_id').value)!=""){*/

		if(trim($F('regpassword'))==""){	
		document.getElementById("regpass_err").innerHTML="<div style='padding-top:9px;'>Please enter password</div>";	
		document.getElementById("regpass_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/unavailable.png";	
		return false;	
		}
		else if($F('regpassword').length < 6){
		document.getElementById("regpass_err").innerHTML="Password must contain<br> at least 6 characters";	
		document.getElementById("regpass_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/unavailable.png";	
		return false;	
		}
		else
		{
		document.getElementById("regpass_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/available.png";	
		document.getElementById("regpass_err").innerHTML="";
		return true
		}
	
	//}
}

function check_Username(txtboxname)
{
		
uname_err=0;
var nameavailability=true;

/*if(trim(document.getElementById('regemail_err').innerHTML)=="" && trim(document.getElementById('regpass_err').innerHTML)=="" && trim(document.getElementById('regpassword').value)!="" && trim(document.getElementById('email_id').value)!=""){*/

	if(trim($F(txtboxname))==""){
	uname_err=1;
	document.getElementById("reguname_err").innerHTML="Username should not be<br> empty";			
	}
	else if($F(txtboxname).length < 4 ){
	uname_err=1;
document.getElementById("reguname_err").innerHTML="Username must have<br> at least four characters";		
	}
	else if(!validUsername($F(txtboxname)) ){
	uname_err=1;
	document.getElementById("reguname_err").innerHTML="Username must not have<br> any special characters!";	
	}	
	else if(!checkWord_exist($F(txtboxname),'aroxo')){
	uname_err=1;
document.getElementById("reguname_err").innerHTML="Sorry, you can\'t use<br> our name in username";		
	}	
	else	
	nameavailability=CheckUsernameAvailability(txtboxname);	
	
	
	if(uname_err==1)
	{
	document.getElementById("regunam_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/unavailable.png";
	return false
	}
	else if(document.getElementById("reguname_err").innerHTML!="") 
	 return false;
	else
	{
	uname_err=0;
	document.getElementById("reguname_err").innerHTML="";	
	document.getElementById("regunam_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/available.png";
	}

	//}

}
var xmlHttpChkAvail;
function CheckUsernameAvailability(txtboxname)
{

xmlHttpChkAvail=GetXmlHttpObject();
		if (xmlHttpChkAvail==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url=document.getElementById("ARX_SiteURL_txt").value+"checkusernameavailability.php?uname=" + $F(txtboxname)
		//alert(url);
		xmlHttpChkAvail.onreadystatechange=getAvailability;
		
		xmlHttpChkAvail.open("GET",url,true);
		xmlHttpChkAvail.send(null);


}

function getAvailability()
{
	if (xmlHttpChkAvail.readyState==4){ 
		var result 	= xmlHttpChkAvail.responseText;	
	//	alert(result);		
		if(trim(result)=="true")
		{
		uname_err=0;
		document.getElementById("reguname_err").innerHTML="";	
		document.getElementById("regunam_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/available.png";
		return true;
		}
		else if(trim(result)=="false")
		{	
		uname_err=1;
		
		if(trim(document.getElementById('regpass_err').innerHTML)!="")
		{
		document.getElementById("regpass_err").innerHTML="";	
		document.getElementById("regpass_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/spacer.gif";
		}
		if(trim(document.getElementById('regemail_err').innerHTML)!="")
		{
		document.getElementById("regemail_err").innerHTML="";	
		document.getElementById("regemail_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/spacer.gif";		
		}
		
		document.getElementById("regunam_errsymbol").src=document.getElementById("ARX_SiteURL_txt").value+"images/unavailable.png";
		document.getElementById("reguname_err").innerHTML="Sorry - some early bird<br> has got that! :(";	
		return false;	
		}
	}

}
		