var fixPNG_arVersion = navigator.appVersion.split("MSIE")
var fixPNG_version = parseFloat(fixPNG_arVersion[1])
function checkemail(email) {
    if (email.length < 11 || email.indexOf("@")==-1 || email.indexOf(".")==-1 || email.indexOf("!")!=-1 || email.indexOf("..")!=-1 || email.indexOf(".")==0 || email.indexOf(".")==email.length|| email.indexOf("test")!=-1 || email.indexOf("hjkl")!=-1 || email.indexOf("yuio")!=-1 || email.indexOf("zxcv")!=-1 || email.indexOf("asdf")!=-1 || email.indexOf("qwer")!=-1)
		return false;
    else {
		var pos;
		pos = email.indexOf("@");
		var mailbox=email.substring(0,pos);
		var domainname=email.substring(pos+1,email.length);
		var mailboxlast=mailbox.substring(mailbox.length-1,mailbox.length);
		var domainfirst=domainname.substring(0,1);
		var lastdigit=email.substring(email.length-1,email.length);
		var firstdigit=email.substring(0,1)
		if (mailbox.indexOf("-")==-1 && domainname.indexOf("_")==-1 && domainname.indexOf("@")==-1 && lastdigit.indexOf(".")==-1 && lastdigit.indexOf("-")==-1 && firstdigit.indexOf(".")==-1 && firstdigit.indexOf("_")==-1 && mailboxlast.indexOf(".")==-1 && mailboxlast.indexOf("_")==-1 && domainfirst.indexOf(".")==-1 && domainfirst.indexOf("-")==-1)
			return true;
		else
			return false;
    }
}

function fixPNG(myImage) 
{
    if ((fixPNG_version >= 5.5) && (fixPNG_version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}
function createRequestObject(){
	var request_o;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_o = new XMLHttpRequest();
	}
	return request_o;
}
var fileLoadingImage = "images/loading.gif";
var fileLoadingImageHeight = 32;
function getContent(url,divID){
	/* The variable http will hold our new XMLHttpRequest object. */
	var divContainer="";
	var redirect_url="";	
	divContainer = divID;
	//document.getElementById(divContainer).style.height= fileLoadingImageHeight + 'px';
	if((x=MM_findObj(divContainer))!=null){
		x.innerHTML +='<div style="position:absolute;left:50%;top:50%;z-index:2;margin-left:-' + (fileLoadingImageHeight/2) + 'px;margin-top:-' + (fileLoadingImageHeight/2) + 'px;display:block;"><img src="' + fileLoadingImage + '" ></div>';
	} else {
		//setTimeout(function(){getContent(url,divID);});
	}
	var http = createRequestObject(); 	
	var queryStr="";

	a = getContent.arguments;	
	for(i=2;i<a.length;i++)
	{
		if(i==(a.length-1)) queryStr = queryStr + a[i];else queryStr = queryStr + a[i] + '&';
	}
	//alert(url + '&' + queryStr);
	//document.write(url + '?' + queryStr);
	if(url.indexOf('?'))http.open('post', url + '&' + queryStr);else http.open('post', url + '?' + queryStr);
	
	/* Define a function to call once a response has been received.  */
	http.onreadystatechange = function(){
			/* Make sure that the transaction has finished. The XMLHttpRequest object 
			has a property called readyState with several states:
			0: Uninitialized
			1: Loading
			2: Loaded
			3: Interactive
			4: Finished */
		if(http.readyState == 1){
			//document.getElementById(divContainer).innerHTML = "Loading";
		}
		if(http.readyState == 4 && http.status == 200){ //Finished loading the response
			/* We have got the response from the server-side script,
				let's see just what it was. using the responseText property of 
				the XMLHttpRequest object. */
			var response = http.responseText;
			/* And now we want to change the product_categories <div> content.
				we do this using an ability to get/change the content of a page element 
				that we can find: innerHTML. */
			
			if(response.toString().indexOf('http://')==0 || response.toString().indexOf('https://')==0){
				document.write('<script language=javascript>window.location.href=\''+ response +'\'</script>')
				http.send(null);
			}else{
					alert(response);
			}
			if((x=MM_findObj(divContainer))!=null){
				x.innerHTML = response;
			} else {
// 				alert('ngepet')
			}
			in_progress = false;
		}
		alert(response);
	}
	/* Send the data.  */
	http.send(null);
}
function postContent(url,divID) {
	var queryStr = "";
	var a = postContent.arguments;
	for (var i=2;i<a.length;i++) {
		queryStr = queryStr + a[i] + '&';
	}
	var html = '<img src="' + fileLoadingImage + '" style="position:absolute;left:50%;top:50%;margin-left:-' + (fileLoadingImageHeight/2) + 'px;margin-top:-' + (fileLoadingImageHeight/2) + 'px;">';
	$("#"+divID).append(html);
	$.ajax({
		type: "POST",
		url: url,
		data: queryStr,
		cache: false,
		success: function(html){
			$("#"+divID).html(html);
			location.href = "#"+divID;
		}
	});
}
// function postContent__20090222(url,divID){
// 	/* The variable http will hold our new XMLHttpRequest object. */
// 	var divContainer="";
// 	var redirect_url="";
// 	var queryStr="";
// 	divContainer = divID;
// 	if((x=MM_findObj(divContainer))!=null){
// 		x.innerHTML +='<img src="' + fileLoadingImage + '" style="position:absolute;left:50%;top:50%;margin-left:-' + (fileLoadingImageHeight/2) + 'px;margin-top:-' + (fileLoadingImageHeight/2) + 'px;">';
// 	} else {
// 		//setTimeout(function(){postContent(url,divID);});
// 	}
// 	var http = createRequestObject(); 
// 	a = postContent.arguments;	
// 	for(i=2;i<a.length;i++)
// 	{
// 		if(i==(a.length-1)) queryStr = queryStr + a[i];else queryStr = queryStr + a[i] + '&';
// 	}	
// 	//if(url.indexOf('?'))http.open('post', url + '&' + queryStr);else http.open('post', url + '?' + queryStr);
// 	
// 	//document.write (url);
// 	//return false;
// 	//alert(divID);
// 	//alert('url' + url);
// 	//alert('queryStr' + queryStr);
// 	http.open('POST', url, true);
// 	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
// 	http.setRequestHeader("Content-length", queryStr.length);
// 	http.setRequestHeader("Connection", "Keep-Alive");
// 	http.send(queryStr);
// 
// 	/* Define a function to call once a response has been received.  */
// 	http.onreadystatechange = function(){
// 			/* Make sure that the transaction has finished. The XMLHttpRequest object 
// 			has a property called readyState with several states:
// 			0: Uninitialized
// 			1: Loading
// 			2: Loaded
// 			3: Interactive
// 			4: Finished */
// 		if(http.readyState == 1){
// 			//document.getElementById(divContainer).innerHTML = "Loading";
// 		}
// 		
// 		if(http.readyState == 4 && http.status == 200){ //Finished loading the response
// 			/* We have got the response from the server-side script,
// 				let's see just what it was. using the responseText property of 
// 				the XMLHttpRequest object. */
// 			var response = http.responseText;
// 			/* And now we want to change the product_categories <div> content.
// 				we do this using an ability to get/change the content of a page element 
// 				that we can find: innerHTML. */
// 			if(response.toString().indexOf('http://')==0||response.toString().indexOf('https://')==0){
// 			document.write('<script language=javascript>window.location.href=\''+ response +'\'</script>')
// 			http.send(null);
// 			}
// 			if((x=MM_findObj(divContainer))!=null){
// 				x.innerHTML = response;
// 			}
// 			in_progress = false;
// 		}
// 	} 
// }
String.prototype.trim = function(){return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );}
function populate_input(form_name){
	var form='';
	var inputs='';
	form=document.forms[form_name];
	el=form.elements;
	for(i=0;i<el.length;i++){
		if(el[i].type=='text'||el[i].type=='password'||el[i].type=='hidden'){
			inputs+=el[i].name.replace('[','{').replace(']','}').replace('id','')+'='+el[i].value+'&';
		}
	}
	return inputs;
}
function MM_findObj(n,d){var p,i,x;if(!d)d=document;if((p=n.indexOf("?"))>0&&parent.frames.length){d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}if(!(x=d[n])&&d.all)x=d.all[n];for(i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);if(!x && d.getElementById) x=d.getElementById(n);return x;}