﻿//Sets MaxLength for TextArea
function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

function changeTitle(title) {
document.title = title;
}

active_fd_x = 0;
function toggleFDMenu(e,a,m,oc,ml) // e= elementid, a= add pic, m= minus pic, oc= open/close(0,1), ml= menu level 
{
	//element = document.getElementById(e).style;
	if ((active_fd_x != 0) && (active_fd_x != e) && (oc == 1) && (ml == 1))
	{
	 	//alert(active_fd_x);
		document.getElementById(active_fd_x + '_sub').style.display='none';
			if (active_fd_x.indexOf('_sub')<0)
				{
				document.getElementById(active_fd_x + '_sub_sub').style.display='none';
				}
			if (active_fd_x.indexOf('_sub')>1)
				{
				document.getElementById(active_fd_x).style.display='none';
				}
		document.getElementById(active_fd_x + '_pic').src = a;
	}
	
	if (document.getElementById(e + '_sub').style.display=='none')
	{
		document.getElementById(e + '_sub').style.display='block';
	 	document.getElementById(e + '_pic').src = m;
		active_fd_x = e;
	} else {
		if (active_fd_x == e)
		{
			document.getElementById(e + '_sub').style.display='none';
	 		document.getElementById(e + '_pic').src = a;
	 	} else {
	 	//alert(e);
	 	//alert(active_fd_x);
			document.getElementById(e + '_sub').style.display='none';
			if (e.indexOf('_sub')<0)
				{
				document.getElementById(e + '_sub_sub').style.display='none';
				}
	 		document.getElementById(e + '_pic').src = a;
	 	}
	}
}





	active_fd_l1 = 0;
	active_fd_l2 = 0;

	//e = element, a = plus img, m = minus img, oc = open or close, ml = menu level (0,1)
	function fdMenu(e, a, m, oc, ml) {
		var thee = document.getElementById(e); var thes = document.getElementById(e + '_sub'); var thep = document.getElementById(e + '_pic');
		var the_act1_s = document.getElementById(active_fd_l1 + '_sub'); var the_act1_p = document.getElementById(active_fd_l1 + '_pic');
		var the_act2_s = document.getElementById(active_fd_l2 + '_sub'); var the_act2_p = document.getElementById(active_fd_l2 + '_pic')
		if (thes.style.display=='none')
		{
			//Should We Close Last Menu?
			if (oc == 1) {
				//Which Sub Menu Level Should Be Closed?
				if (ml == 0) {
					if (active_fd_l1 != 0) {
						the_act1_s.style.display = 'none';
						the_act1_p.src = a;
					}
				} else {
					if (active_fd_l2 != 0) {
						the_act2_s.style.display = 'none';
						the_act2_p.src = a;
					}
				}
			}
			thes.style.display = 'block';
			thep.src = m;
			//Sets the Active Menu (Last Menu Clicked)
			if (ml == 0) {active_fd_l1 = e;} else {active_fd_l2 = e;}
		} 
		else 
		{
			thes.style.display='none';
			thep.src = a;
		}
	}
	//0: identity, 1: plus profile
	function MembersSignUpValidate(this_profiletype,adr,adr2,zc,ct,cn,ctr,tel,fax,mob,pic) { 
		isValid = true;
		var ErrMsg = ":ايرادات زير در فرم تکميل شده وجود دارد\n\n";
		var re;
		var str;
		
		str = document.getElementById('memberssignup_fullname').value;
	    if (str.length < 4)
	    {
	        ErrMsg = ErrMsg + "                        نام و نام خانوادگی -\n";
	        isValid = false;
	    }
	    
	    str = document.getElementById('memberssignup_username').value;
	    re = /^[a-zA-Z0-9]{3,20}$/;
	    str = str.toString( );
	    if (!str.match(re)) {
	        ErrMsg = ErrMsg + "                             شناسه کاربری -\n";
	        isValid = false;
	    }
	    
	    str = document.getElementById('memberssignup_password').value;
	    str2 = document.getElementById('memberssignup_repassword').value;
	    if ((str.length < 5)||(str != str2))
	    {
	        ErrMsg = ErrMsg + "                                     کلمه عبور -\n";
	        isValid = false;
	    }
	    
	    str = document.getElementById('memberssignup_emailaddress').value;
	    re = /^(([^<>()[\]\\.,;:\s@""]+(\.[^<>()[\]\\.,;:\s@""]+)*)|("".+""))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	    str = str.toString( );
	    if (!str.match(re)) {
	        ErrMsg = ErrMsg + "                                  آدرس ايميل -\n";
	        isValid = false;
	    }
	    
	    
	    //Check Profile If It Should Be Checked
	    if (this_profiletype == 1) {
	    	ErrMsg = ErrMsg + '\n';
	    	
	    	if (adr == 'on') {
			    str = document.getElementById('memberssignup_address1').value;
			    if (str.length < 5)
			    {
			        ErrMsg = ErrMsg + "                                         نشانی -\n";
			        isValid = false;
			    }
		    }

	    	if (zc == 'on') {
			    str = document.getElementById('memberssignup_zipcode').value;
			    if (str.length < 4)
			    {
			        ErrMsg = ErrMsg + "                                     کد پستی -\n";
			        isValid = false;
			    }
			}
			
	    	if (ct == 'on') {
			    str = document.getElementById('memberssignup_city').value;
			    if (str.length < 3)
			    {
			        ErrMsg = ErrMsg + "                                            شهر -\n";
			        isValid = false;
			    }
			}

	    	if (ctr == 'on') {
			    str = document.getElementById('memberssignup_country').value;
			    if (str.length < 3)
			    {
			        ErrMsg = ErrMsg + "                                           کشور -\n";
			        isValid = false;
			    }
			}

	    	if (tel == 'on') {
			    str = document.getElementById('memberssignup_telephone').value;
			    re = /^([+]{1}|[0]{2})[0-9]{1,3}[-|.|\s]{0,1}[0-9]{7,11}$/;
			    str = str.toString( );
			    if (!str.match(re)) {
			        ErrMsg = ErrMsg + "     شماره تلفن 00982187654321 -\n";
			        isValid = false;
			    }
			}

	    	if (mob == 'on') {
			    str = document.getElementById('memberssignup_mobile').value;
			    re = /^(09){1}[0-9]{9}$/;
			    str = str.toString( );
			    if (!str.match(re)) {
			        ErrMsg = ErrMsg + " شماره تلفن همراه 09121234567 -\n";
			        isValid = false;
			    }
			}

	    }	    
	    
	    //Showing Error And Return False
	    
	    if (!isValid) {
	    	ErrMsg = ErrMsg + "\n.لطفا فرم را با دقت بيشتری تکميل کنيد"
	    	alert(ErrMsg);
	    	}
	    	    
	    return isValid;		
	}
	


	// UPDATE PROFILE ********************************************************
	//0: identity, 1: plus profile
	function MembersEditProfileValidate(this_whichdata, this_profiletype,adr,adr2,zc,ct,cn,ctr,tel,fax,mob,pic) { 
		isValid = true;
		var ErrMsg = ":ايرادات زير در فرم تکميل شده وجود دارد\n\n";
		var re;
		var str;
		
		if ((this_whichdata == 4) || (this_whichdata == 6)) {
			str = document.getElementById('memberseditprofile_fullname').value;
		    if (str.length < 4)
		    {
		        ErrMsg = ErrMsg + "                        نام و نام خانوادگی -\n";
		        isValid = false;
		    }
		}
			    
	    str = document.getElementById('memberseditprofile_password').value;
	    if (str.length < 5)
	    {
	        ErrMsg = ErrMsg + "                                     کلمه عبور -\n";
	        isValid = false;
	    }
	    
		if ((this_whichdata == 2) || (this_whichdata == 6)) {
		    str = document.getElementById('memberseditprofile_emailaddress').value;
		    re = /^(([^<>()[\]\\.,;:\s@""]+(\.[^<>()[\]\\.,;:\s@""]+)*)|("".+""))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		    str = str.toString( );
		    if (!str.match(re)) {
		        ErrMsg = ErrMsg + "                                  آدرس ايميل -\n";
		        isValid = false;
		    }
		}	    
	    
	    //Check Profile If It Should Be Checked
	    if (this_profiletype == 1) {
	    	ErrMsg = ErrMsg + '\n';
	    	
	    	if (adr == 'on') {
			    str = document.getElementById('memberseditprofile_address1').value;
			    if (str.length < 5)
			    {
			        ErrMsg = ErrMsg + "                                         نشانی -\n";
			        isValid = false;
			    }
			}

	    	if (zc == 'on') {
			    str = document.getElementById('memberseditprofile_zipcode').value;
			    if (str.length < 4)
			    {
			        ErrMsg = ErrMsg + "                                     کد پستی -\n";
			        isValid = false;
			    }
			}

	    	if (ct == 'on') {
			    str = document.getElementById('memberseditprofile_city').value;
			    if (str.length < 3)
			    {
			        ErrMsg = ErrMsg + "                                            شهر -\n";
			        isValid = false;
			    }
			}
	
	    	if (ctr == 'on') {
			    str = document.getElementById('memberseditprofile_country').value;
			    if (str.length < 3)
			    {
			        ErrMsg = ErrMsg + "                                           کشور -\n";
			        isValid = false;
			    }
			}
	
	    	if (tel == 'on') {
			    str = document.getElementById('memberseditprofile_telephone').value;
			    re = /^([+]{1}|[0]{2})[0-9]{1,3}[-|.|\s]{0,1}[0-9]{7,11}$/;
			    str = str.toString( );
			    if (!str.match(re)) {
			        ErrMsg = ErrMsg + "     شماره تلفن 00982187654321 -\n";
			        isValid = false;
			    }
			}
	
	    	if (mob == 'on') {
			    str = document.getElementById('memberseditprofile_mobile').value;
			    re = /^(09){1}[0-9]{9}$/;
			    str = str.toString( );
			    if (!str.match(re)) {
			        ErrMsg = ErrMsg + " شماره تلفن همراه 09121234567 -\n";
			        isValid = false;
			    }
			}
	    }	    
	    
	    //Showing Error And Return False
	    
	    if (!isValid) {
	    	ErrMsg = ErrMsg + "\n.لطفا فرم را با دقت بيشتری تکميل کنيد"
	    	alert(ErrMsg);
	    	}
	    	    
	    return isValid;		
	}
	
	
	
	
	function FAQValidate() { 
		isValid = true;
		var ErrMsg = ":ايرادات زير در فرم تکميل شده وجود دارد\n\n";
		var re;
		var str;
		
		str = document.getElementById('askfaq_name').value;
	    if (str.length < 4)
	    {
	        ErrMsg = ErrMsg + "                        نام و نام خانوادگی -\n";
	        isValid = false;
	    }
	    
	    str = document.getElementById('askfaq_email').value;
	    re = /^(([^<>()[\]\\.,;:\s@""]+(\.[^<>()[\]\\.,;:\s@""]+)*)|("".+""))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	    str = str.toString( );
	    if (!str.match(re)) {
	        ErrMsg = ErrMsg + "                                  آدرس ايميل -\n";
	        isValid = false;
	    }
	    
	    str = document.getElementById('askfaq_heading').value;
	    if (str.length < 3)
	    {
	        ErrMsg = ErrMsg + "                                 عنوان سوال -\n";
	        isValid = false;
	    }

	    str = document.getElementById('askfaq_question').value;
	    if (str.length < 3)
	    {
	        ErrMsg = ErrMsg + "                                    متن سوال -\n";
	        isValid = false;
	    }


	    //Showing Error And Return False
	    
	    if (!isValid) {
	    	ErrMsg = ErrMsg + "\n.لطفا فرم را با دقت بيشتری تکميل کنيد"
	    	alert(ErrMsg);
	    	}
	    	    
	    return isValid;		
	}