/**
 * @package pearltea
 * @copyright Copyright 2007 LightInTheBox Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: frmCheck.js - create by tankai 2007-10-19 
 */
var baseURL = "http://www.kisolar.com/";
var langs="en";

var lang_txt = new Array();
lang_txt['checkemail'] = 'Please check your email address.\nYour email addresses should look like "myname@gmail.com"';
lang_txt['bookm'] = 'AddThis Social Bookmarking Widget';
lang_txt['notice_12_22'] = '<strong>IMPORTANT NOTICE:</strong> Dear Customers, after <strong>Sunday 21 Dec 17:00 (PST)</strong> we can no longer guarantee items ordered from LightInTheBox.com will arrive before Christmas Day. We are still working hard over the Holidays to source, pack and ship the best quality products, so you are invited to browse now for 2009. <br />Merry Christmas and a Happy New Year from everyone at LightInTheBox!';
lang_txt['notice_1_22'] = '<strong>5%</strong> Off Promotion for the Chinese New Year. Order between <strong>Jan 22</strong> and <strong>Feb 1 (PST)</strong> to receive a <strong>5% discount on all items</strong> at LightInTheBox.com. For more details on this exclusive offer, <a href="http://www.lightinthebox.com/html/notice.html" class="u">click here</a>.'
lang_txt['page_nav_text']=['page', 'Previous', 'Next', 'of'];
lang_txt['back_to_top']=['Back to top'];
lang_txt['pageText']='Displaying';
lang_txt['reviewer_image_text']=['Reviewer Images', '(click to see full-size image)'];
lang_txt['ADDART']='Add to Cart';
lang_txt['ATTRIBUTESELECT']='Please Select';
lang_txt['WIN_OPEN_TITLE']='Help LightInTheBox to serve you better. ';
lang_txt['WIN_OPEN_CON']='Please take 2 mins to answer a few short questions about our website. Thank you! ';
lang_txt['WIN_OPEN_BUTTON_NEVER']='Never';
lang_txt['WIN_OPEN_BUTTON_LATER']='Later';
lang_txt['WIN_OPEN_BUTTON_NOW']='Now';
lang_txt['FRM_CHECK_TEXT']=[
	"The two passwords you entered don't match. Please try again.",
	"Are you sure your ",
	" is correct? E-mail addresses must contain an \"at\" sign (@) and a period (.) somewhere to the right of the @, with no spaces or commas. (Example: yourname@hotmail.com)",
	"Is your ",
	" correct? Sorry, my system does not understand your telephone format.",
	"Your ",
	" must contain a minimum of ",
	" characters.",
	" correct? Our system requires a maximum of ",
	"a valid email address",
	"a password ",
	"you need to confirm your",
	"Sorry, you need to ",
	"Sorry, ",
	" is required.",
	"a \"Title\"",
	"Please choose ",
	"Are you sure you want to delete reviews?",
	"Full name information is required.",
	"E-mail address information is required.",
	"Are you sure your email address is correct? An email address should contain the \"@\" and \".\" characters.",
	"Phone information is required.",
	"phone must be number",
	"QTY information is required.",
	"Quantity (Qty.) must be a number.",
	"Minimum Quantity (Qty.) is 3 units.",
	"Any questions about delivery, products or any special instructions about your order, write it down here.",
	"Inquiry information is required.",
	"Your inquiry is too long. The maximum length is 500 characters.",
	"Name is too long. The maximum length is 50 characters.",
	"Phone number cannot contain letters and must be less than 20 characters long.",
	"Please enter the validation code in the box provided.",
	"The validation number you entered is incorrect.",
    "Please Choose Your Country.",
    "Please Choose Your Describes.",
	"Please enter the ",
	" in this format: 0911020100375457.",
        "The two email address you entered don't match. Please try again.",
	"Phone number is invalid.",
	"Your phone number must be at least 9 digits."

];
lang_txt['TEXT_PLEASE_SELECT']='Please Select';
////
lang_txt['view_large_image_next'] = 'next';
lang_txt['view_large_image_back'] = 'back';
lang_txt['save'] = 'Save';
lang_txt['freeshipping'] = 'Free Shipping';
lang_txt['retailprice'] = 'Retail Price';
lang_txt['view_orders_paypal_first'] = 'The order status shall be updated from pending to apropos status in 48 hours after you placed and paid your order. If you pay again for this order via the button below, it will be updated to a new order. are you continue?';
lang_txt['view_orders_paypal'] = 'Thank you, we have received the payment for your order, and it is now processing. Please do not try to resend your payment again.';
lang_txt['searchTicketId'] = 'Please submit valid ticket number!';
var lang = new Array();
lang['save'] = 'Save';
lang['freeshipping'] = 'Free Shipping';
lang['retailprice'] = 'Retail Price';
lang_txt['Required'] = '*Required';
lang_txt['customer_say'] = '"http:\/\/www.lightinthebox.com\/index.php?main_page=testimonials" class="more_product" title="More Customer Testimonials">';
lang_txt['more_customer'] = 'More Customer Testimonials &gt;&gt;';
lang_txt['star']='Star';
lang_txt['stars']='Stars';
lang_txt['custom'] = 'Custom';




var _Arr=lang_txt['FRM_CHECK_TEXT'];
function field_check(name, rule, field){
	
   
  	if(rule.indexOf("cpwd")>-1){
		strTmp = rule.split("#");
		tempFuc=jQuery("#"+strTmp[1])[0].value;
		if(strTmp[0].inc("cpwd","/") == true && field.value != tempFuc){
			return _Arr[0];
		
			//return "The "+name+" must match your " +name.split(" Confirmation")[0];
		}
	}
	if(rule.indexOf("cemaild")>-1){
		strTmp = rule.split("#");
		if(strTmp[0].inc("cemaild","/") == true && field.value != jQuery("#"+strTmp[1]).value){
			return _Arr[37];
		
			//return "The "+name+" must match your " +name.split(" Confirmation")[0];
		}
	}
	if(rule.inc("eml","/")==true && !/(\,|^)([\w+._]+@\w+\.(\w+\.){0,3}\w{2,4})/.test(field.value.replace(/-|\//g,"")) && !isNone(field.value)){
		return _Arr[1] + name + _Arr[2];
	}	


	if(rule.inc("number","/")==true&&!new RegExp("^[0-9]*$","g").test(field.value)){
		return _Arr[35]+name+_Arr[36];
	}
	size = rule.sub("min","/");
	if(size > 0 ){			
		if(field.value.trim().length < size && field.value.trim().length>0){
			return _Arr[5]+ name +_Arr[6]+size+_Arr[7];
		}
	}		
	size = rule.sub("max","/");		
	if(size > 0 ){
		if(field.value.trim().length > size){
			return _Arr[3]+ name +_Arr[8]+size+_Arr[7];
		}
	}	
	if(rule.inc("nnull","/") == true && isNone(field.value)){
		switch(langs){
			case "en":
				switch(name){
					case "Email address":
						if(rule.inc("reg","/") == true) return _Arr[13]+name.toLowerCase()+_Arr[14];
						else name = _Arr[9];
						break;
					case "Password":
						if(rule.inc("reg","/") == true) return _Arr[13]+name.toLowerCase()+_Arr[14];
						else name = _Arr[10];
						break;
					case "password confirmation":
						return _Arr[13]+_Arr[11];
						break;
					default:
						name = name;
				}
				if(rule.inc("reverse","/") == true){
					return _Arr[10]+name;
				}else{
					return _Arr[13]+name+_Arr[14];
				}
			default:
			return _Arr[13]+name+_Arr[14];
		}
	}	

	if(rule.inc("def","/") == true){
			if(field.value == jQuery(field).attr("mvalue")){
				return _Arr[13]+name+_Arr[14];
			}
	}	
	if(rule.inc("ischeck","/") == true && ! field.checked ){
		return name;
	}
	if(rule.inc("isselect","/") == true && field.value == '-1' ){

		switch(langs){
			case "fr":
				return _Arr[40] + " \<\< " + name + "\>\>";
			case "de":
				return  _Arr[40] + '"' + name + '"';
			case "ja":
				return  '「' + name + '」 '+_Arr[16]; //日语语序变更
			default:
				switch(name){
					case "Title":
						name = _Arr[15];
						break;
					default:
					if(langs != "it")
						name = '"' + name + '"';
				}
				return _Arr[16] + name;
		}

	}
	if(rule.inc("tel","/")==true){

		if(!/(^[0-9+\s\-\,\(\)]{0,45}$)/.test(field.value)){
			return _Arr[38];
		}else {
			var _v = field.value.replace(/\s/g,'');	
			var _arr = ["aa","ab","ac","ad","ae","bb","ba","bc","bd","be","cc","ca","cb","cd","ce","dd","da","db","dc","de","ee","ea","eb","ec","ed","ff"];
			var __v=field.value.replace(/\-/g,'a').replace(/\+/g,'b').replace(/\,/g,'c').replace(/\(/g,'d').replace(/\)/g,'e').replace(/\s/g,'f');	
			for(var i=0;i<_arr.length;i++){	
				var _reg=new RegExp(_arr[i], "gi");
				if(_reg.test(__v)){
					return _Arr[38];
					break;
				}
			}
			if(_v.replace(/[^\x00-\xff]/g,"  ").length>22){
				return _Arr[38];
			}
			if(_v.replace(/\D/g,"").length<9){
				return _Arr[39];
			}
			
				
		}
	}	
	return "";
};

/*#表单验证#*/
function fmChk(fm){
	
	//return false;
	var name , rule , tmp , msgStr , size;
	
	if(fm == null || fm.tagName != "FORM"){
		alert("", null , "error");
	    return;
	}	
	for(i=0;i<fm.length;i++){		
		var msgStr = chkInput(fm[i]);				
		if(msgStr != "success"){
			efocu(fm[i]);
			msg(msgStr);
			return false;
		}
	}
	return true;
};
/*#表单验证#*加上某些不需要验证的情况*/
function fmChk_Reason(fm,whichone){
	var name , rule , tmp , msgStr , size;
	if(fm == null || fm.tagName != "FORM"){
		alert("", null , "error");
	    return;
	}	

	for(i=0;i<fm.length;i++){	

		
		var msgStr = chkInput_Reason(fm[i],whichone);				
		if(msgStr != "success"){
			efocu(fm[i]);
			msg(msgStr);
			return false;
		}
	}
	return true;
};
function chkInput(obj){
	var name , rule , msgStr;
	name=obj.getAttribute("chkName");
	rule=obj.getAttribute("chkRule");
	if(isNone(rule) || isNone(name))  return "success";	
	msgStr = field_check(name, rule, obj);
	if(msgStr != ""){
		return msgStr;
	}
	else{
		return "success";
	}
};
/*#表单验证#*加上某些不需要验证的情况*/
function chkInput_Reason(obj,whichone){
	var name , rule , msgStr;
	name=obj.getAttribute("chkName");
	rule=obj.getAttribute("chkRule");
	if(isNone(rule) || isNone(name))  return "success";	
	if(name==whichone) return "success";
//	alert(name);
//	alert(whichone);
	if(name==whichone) {
		alert(name);
		return "success";
	}
	msgStr = field_check(name, rule, obj);
	
	if(msgStr != ""){
		return msgStr;
	}
	else{
		return "success";
	}
};

function msg(key){
	alert(key);
};
function initForm(el, func){	
	var img_path = baseURL + "includes/templates/lite_green/images/icons";
	(new Image(10,10)).src = img_path + "/ico_F.gif";
	var error_bg = "#FEDFDF", blur_bg = "" , focus_bg = "#FFFEE1";
	var formId = jQuery("#"+el)[0];
	if(formId == null || formId.tagName != "FORM"){
		alert("", null , "error");
	    return;
	}
	var addImage = '<img src="'+ img_path + "/ico_T.gif" +'" width="10" height="10" style="display:none;" class="pad_l"/>';
	var addDiv = '<div style="display:none;" class="red line_120 mar_t2"></div>';
	var elArr = formId.elements;
	var elLen = elArr.length;
	for(i=0; i<elLen; i++) {
		//insert the img and div
		var addHtml = elArr[i].getAttribute("chkRule");
		if(addHtml){
			insHtm(elArr[i],addImage);
			insHtm(elArr[i],addDiv);
			
			//add the mouse style have check;
			elArr[i].onfocus = function(){
					if((this.tagName === "INPUT" && (this.type === "text" || this.type === "password"))||this.tagName === "TEXTAREA")
					{this.style.backgroundColor = focus_bg;}
			}
			elArr[i].onblur = function(){
				this.style.backgroundColor = blur_bg;	
				var out_img = this.parentNode.getElementsByTagName("img")[0];
				var out_text = this.parentNode.getElementsByTagName("div")[0];
				var msg = chkInput(this);
				if(msg === "success") {
					if(this.getAttribute("islps")&&this.value==""){
						out_img.src = img_path + "/tran.gif?49247";
					}else{
						out_img.src = img_path + "/ico_T.gif?49247";
					}
					out_img.style.display="inline";
					out_text.style.display="none";
				}else{
					loginCheckLog({name:this.name,action:"action_log"});
					out_img.src = img_path + "/ico_F.gif?49247";						
					out_img.style.display="inline";
					out_text.innerHTML = msg;
					out_text.style.display="block";
					if((this.tagName === "INPUT" && (this.type === "text" || this.type === "password"))||this.tagName === "TEXTAREA"){
						this.style.backgroundColor = error_bg;
					}
				}
				if(func != null) {try{eval(func);}catch(e){}}						
			}
		}else{
				//add the mouse style not check;
			if((elArr[i].tagName === "INPUT" && (elArr[i].type === "text" || elArr[i].type === "password"))||elArr[i].tagName === "TEXTAREA"){
				elArr[i].onfocus = function(){this.style.backgroundColor = focus_bg;}
				elArr[i].onblur = function(){this.style.backgroundColor = blur_bg; if(func != null) {try{eval(func);}catch(e){}}}
			}
		}
	}
}
function deletereview(){
	var a=confirm(_Arr[17]);
	if(a)
	{
		document.delete_review.submit();
	}
}
function deletereviewone(id,se){
var a=confirm(_Arr[17]);
	if(a)
	{
	document.location.href="index.php?main_page=manage_reviews&yy="+id+"&se="+se;
	}
}

function checkPopform(){
	var _Arr=lang_txt['FRM_CHECK_TEXT'];

	var name=jQuery(".name_win").val();
	var mail=jQuery(".mail_win").val();
	var inq=jQuery(".inq_win").val();
	var phone=jQuery(".phone_win").val();
	var qty=jQuery(".qty_win").val();

	
	if(name.replace(/\s/g,'')==""){
		alert(_Arr[18]);
		return false;
	}else if(name.length>50){
		alert(_Arr[29]);
		return false;
	}
	if(mail.replace(/\s/g,'')==""){
		alert(_Arr[19]);
		return false;
	}
	if(!/(\,|^)([\w+._]+@\w+\.(\w+\.){0,3}\w{2,4})/.test(mail.replace(/-|\//g,""))){
		alert(_Arr[20]);
		return false;
	}
	if(document.getElementById("in_describes").value==-1){
		alert(_Arr[34]);
		return false;
	}
	if(document.getElementById("in_country").value==-1){
		alert(_Arr[33]);
		return false;
	}
	
	var ph = /[^a-z]{1,20}$/;
	if(phone.replace(/\s/g,'')==""){
		alert(_Arr[21]);
		return false;
	}else if(!ph.test(phone) || phone.length>20){
		alert(_Arr[30]);
		return false;
	}
		//alert(qty.value);
	var re =/^[0-9]+$/;
	if(qty.replace(/\s/g,'')==""){
		
		alert(_Arr[23]);
		return false;
	}else if(!re.test(qty)){
		alert(_Arr[24]);
		return false;
	}else if(qty<3){
		alert(_Arr[25]);
		return false;
	}
	if(inq.replace(/\s/g,'')==""||inq==_Arr[26]){
		alert(_Arr[27]);
		return false;
	}else if(inq.length>500){
		alert(_Arr[28]);
		return false;
	}
	if(!document.getElementById("in_check").value){
		alert(_Arr[31]);
		return false;
	}
	return true;
	//$(".popFormIn form").submit();

}
function fmChk_More_Reason(fm,whichone){
	
	var name , rule , tmp , msgStr , size;
	if(fm == null || fm.tagName != "FORM"){
		alert("", null , "error");
	    return;
	}	

	for(i=0;i<fm.length;i++){	

		
		var msgStr = chkInput_More_Reason(fm[i],whichone);				
		if(msgStr != "success"){
			efocu(fm[i]);
			msg(msgStr);
			return false;
		}
	}
	return true;
};
/*#表单验证#*加上某些不需要验证的情况*/
function chkInput_More_Reason(obj,whichone){
	var name , rule , msgStr;
	name=obj.getAttribute("chkName");
	id=obj.getAttribute("id");
	rule=obj.getAttribute("chkRule");
	if(isNone(rule) || isNone(name))  return "success";	
	
//alert(whichone);
//var whichone;
	if(!whichone) return 'success';
	var bbb = whichone.split(",");
	count = (bbb.length);
	for(var i=0; i<=count-2; i++)
  	{//alert(name);
		if(bbb[i] == id) return "success";
	}

	msgStr = field_check(name, rule, obj);
	
	if(msgStr != ""){
		return msgStr;
	}
	else{
		return "success";
	}
};

