﻿// JScript File

function Back()
{
    history.back()
}
function Register(link)
{
    window.close();
    window.opener.location.href = link;    
}

var SpecialChars=';##--##<##>'
function SpecialCharsChecking(val, args)
{
try
{
    var SpecialCharsList =new Array()
    SpecialCharsList=SpecialChars.split('##')    
    args.IsValid =true     
    for (var i=0;i<SpecialCharsList.length;i++)
    {      
            if(args.Value.indexOf(SpecialCharsList[i])!=-1)
            {
                args.IsValid=false
                break;               
            }     
    }  
   
   
 }
 catch(e)
 {}
}

//function  ShowSearchAvdvancedCnt()
//{


//   document.getElementById("TRSearchCnt").style.display="none";
//  document.getElementById("TRtpnlClassifications").style.display="none";
//  document.getElementById("TRtpnlSearchAdvanced").style.display=""
//  document.getElementById("TDadvancedSrch").className="tabStyleSelected";
//  document.getElementById("TDadvancedSrchMain").className="";
//alert(document.getElementById( '<%= imgleftCrnTabAdvaSearch.ClientID %>' ).src);

//  
//  document.getElementById( '<%= imgleftCrnTabAdvaSearch.ClientID %>' ).src=document.getElementById( '<%= imgleftCrnTabAdvaSearch.ClientID %>' ).src.replace('leftCrnTab.gif','leftCrnTabSelected.gif');
// document.getElementById( '<%= imgrightCrnTabAdvaSearch.ClientID %>' ).src=document.getElementById( '<%= imgrightCrnTabAdvaSearch.ClientID %>' ).src.replace('rightCrnTab.gif','rightCrnTabSelected.gif');



////   document.getElementById("TRSearchCnt").style.display="none";
////   document.getElementById("TRtpnlClassifications").style.display="none";
////   document.getElementById("TRtpnlSearchAdvanced").style.display="";
//   
////    document.getElementById("TDadvancedSrch").className="advancedSrchSelected" 
////    document.getElementById("TDsrch").className="srchUnSelected" 
////    document.getElementById("TDcompanyClassifications").className="companyClassUnSelected" 
//}

//function  ShowSearchCnt()
//{


////    document.getElementById("TRSearchCnt").style.display="";
////    document.getElementById("TRtpnlClassifications").style.display="none";
////    document.getElementById("TRtpnlSearchAdvanced").style.display="none";
////    document.getElementById("TDadvancedSrch").className="advancedSrchUnSelected" 
////    document.getElementById("TDsrch").className="srchSelected" 
////    document.getElementById("TDcompanyClassifications").className="companyClassUnSelected" 


//}

//ShowSearchCompanyClassifications

// function  ShowSearchCompanyClassifications()
//{
//    document.getElementById("TRSearchCnt").style.display="none";
//    document.getElementById("TRtpnlClassifications").style.display="";
//    document.getElementById("TRtpnlSearchAdvanced").style.display="none";
//    document.getElementById("TDadvancedSrch").className="advancedSrchUnSelected" 
//    document.getElementById("TDsrch").className="srchUnSelected" 
//    document.getElementById("TDcompanyClassifications").className="companyClassSelected" 
//}
//   
///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/////			NewsLetter Subscribtion Validation				//////////////
/////			By Mohammed yousef khraiast @20-12-2008  		//////////////
//////////////////////////////////////////////////////////////////////////////

function SubscribeUser(lang)
{
//debugger;
var Pagelng=lang
	var strUserEmail = Trim(document.getElementById("userEmailAddress").value) ;
	if (strUserEmail == "")
	{
			if (Pagelng==0)
			    {
			    alert("الرجاء إدخال  العنوان البريدي ") ;
			    }
			    else
			    {
			    alert("Please insert your Email ") ;
			    }
			
			return false ;
	}
	else 
	{
	 if( !(isValidEmail(strUserEmail)) )
	  {	
		
		if (Pagelng==0)
			    {
			  alert("الرجاء إدخال  العنوان البريدي  على الشكل التالي:name@domain.com");
			    }
			    else
			    {
			alert("Please insert your email as the following form :"+ "\n name@domain.com");
			    }
		
		
		
		document.getElementById("userEmailAddress").focus();		
		return false ;
	  }
	   // if every thing goes well 
	   SaveUser(strUserEmail,lang) ;
	   
	}
}

function SaveUser(strUserEmail,lang)
{
	
	//debugger;
	// save the user by loading a template XML file 
	// containing Insert SP. and check the return value
	var cu_no  = "-1" ;
	var result = "-1" ; // to indicate error as default	
	var lblResult = document.getElementById("subscribtionResult") ;
	var Pagelng=lang
		
	if( document.getElementById("cu_no") )
	{
		cu_no = document.getElementById("cu_no").value ;
	}
	else
	{
		alert("could not find cu_no input") ;
		return false ;
	}

	// apply an HTTPRequest
	// send an HTTPRequest to save the data on an ASP page

	var objHTTPRequest;
	try
	{
		// IE
		objHTTPRequest = new ActiveXObject("MSXML2.XMLHTTP") ;
	
	}
	catch( e )
	{
		//firefox
		objHTTPRequest=new XMLHttpRequest();
	}
	
	var strURL = "/site/xml/topics/Newsletter/SubscNewsletter.asp?cu_no=" + cu_no + "&email=" + strUserEmail ;	

	try
	{
	
		objHTTPRequest.open("POST",strURL,false) ; // false for asyncronous call
												   // which means wait tell the page
											       // is fully executed, and read the returned value
		// send the request
		objHTTPRequest.send("");
		
		// check the result
		switch(objHTTPRequest.responseText)
		{
			case "0" : // already used email
				
				if (Pagelng==0)
			    {
	            	alert ("هذا البريد الإلكتروني مستخدم مسبقاً");
	            	//return false;
			    }
			    else
			    {
	            	alert ("This email is already used");
			    }
				
				break ;
			case "1" : // email saved correctly
				//شكرا لك، لقد تم إضافتك الى قائمتنا البريدية
						if (Pagelng==0)
			    {
	            	alert ( unescape("%u0634%u0643%u0631%u0627%20%u0644%u0643%u060C%20%u0644%u0642%u062F%20%u062A%u0645%20%u0625%u0636%u0627%u0641%u062A%u0643%20%u0627%u0644%u0649%20%u0642%u0627%u0626%u0645%u062A%u0646%u0627%20%u0627%u0644%u0628%u0631%u064A%u062F%u064A%u0629"));
			    }
			    else
			    {
	            	alert ("Thank you for subscribing Newsletter");
			    }
				
				document.getElementById("userEmailAddress").disabled = true ;
				break ;
			default : // Error
			  if (Pagelng==0)
			    {
	            	alert ( "نأسف ، لقد حدثة مشكلة خلال عملية الحفظ");
			    }
			    else
			    {
	              alert ("Sorry, There was an error during saving process");
			    }
	 		break ;
		}	
	}
	catch(e)
	{
		alert(e.description);
		return false ;
	}

	objHTTPRequest =  null ;
}
///////////////////////////Auto Complete 05-May-2009////////////////////////////
///////////////////////////////By Mohammed Qandil///////////////////////////////
//This function to replace the HTML codes in a string to the original chars.
function ReplaceChars(inputStr)
{
    var outputStr;
    outputStr=inputStr.replace(/&nbsp;/g," ");//Replace white spaces.
    outputStr=outputStr.replace(/&amp;/g,"&");//Replace ampersand.
    
    return outputStr;
}//End ReplaceChars
////////////////////////////////End Auto Complete///////////////////////////////
