function Void(){
	
}
//check for the needle in given stirng 
function strstr (haystack, needle, bool) {
   var pos = 0;
   haystack += '';
    pos = haystack.indexOf( needle );    if (pos == -1) {
        return false;
    } else{
        if (bool){
            return haystack.substr( 0, pos );        } else{
            return haystack.slice( pos );
        }
    }
}

//Toogle data
function ToogleData(divid){
	jQuery('#'+divid).slideToggle("slow");
}

//display if none or none i display	
function DisplayEditicons(idv){
	var obj    = document.getElementById(idv);
	if(obj.style.display == 'none'){
		obj.style.display = 'block';
	}else{
		obj.style.display = 'none';
	}
}

//this will trim the string bothe left and right
function trim(str) { 
    if (str != null) {
        var i; 
        for (i=0; i<str.length; i++) {
            if (str.charAt(i)!=" ") {
                str=str.substring(i,str.length); 
                break;
            } 
        }     
        for (i=str.length-1; i>=0; i--) {
            if (str.charAt(i)!=" ") {
                str=str.substring(0,i+1); 
                break;
            } 
        }         
        if (str.charAt(0)==" ") {
            return ""; 
        } else {
            return str; 
        }
    }
}

//Check the url
function CheckUrl(url){
	var strRegex = /^[\w\.-]+\.[a-z]{2,6}$/; 
	if(url.substr(0,7) == 'http://'){
		url = url.substr(7,url.length);
	}
	if(url.substr(0,4) == 'www.'){
		url = url.substr(4,url.length);
	}
	if( strRegex.test(url) ){
		return url;
	}else{
		return false;
	}
} 
function ret(formid){
	document.getElementById(formid).submit();
}
function UpdateSite(url,term){
	document.getElementById("loading").style.display="block";
	document.getElementById("loading").innerHTML = 'Please Wait while we update the site <br><img src="'+readCookie('SITE_PATH')+'images/ajax_loader.gif" border=0 style="display:inline;margin-top:10px;">';
	document.getElementById("loadingbg").style.display="block";					
	SubmitFormData(url, '', term);
}
function Addfeed(){
	var url = document.getElementById("urf").value;
	var feed = document.getElementById("feed").value;
	if(trim(feed) == ''){
		alert("Please Enter a Valid Feed URL");
		return false;
	}
	document.getElementById("loading").style.display="block";
	document.getElementById("loading").innerHTML = 'Please wait while we Check the Feed URL<br><img src="'+readCookie('SITE_PATH')+'images/ajax_loader.gif" border=0 style="display:inline;margin-top:10px;">';
	document.getElementById("loadingbg").style.display="block";	
	SubmitFormData(readCookie('SITE_PATH')+'process.php?uri='+url+'&action=feed&feed='+feed, '', 'loading');
}
function SearchDomain(url,term){
	document.getElementById(term).innerHTML = 'Please Wait while we Search the Domain <br><img src="'+readCookie('SITE_PATH')+'images/ajax_loader.gif" border=0 style="display:inline;margin-top:10px;">';
	SubmitFormData(url, '', term);
	return false;
}
//This function will handle all the ajax requests
function SubmitFormData(uri,formid,term){
	var pars = $('#'+formid).serialize();
	$.ajax({
		   type: "POST",
		   url: uri,
		   data: pars,
		   success: function(newData){
		  		if(newData == 'No'){
					/* check for any divids and This Will assign response to some other div Other than the info box messages*/
					document.getElementById("loading").style.display="block";
					document.getElementById("loading").innerHTML = term+ ' is new to us! <br> Please wait while we create the page... <br><img src="'+readCookie('SITE_PATH')+'images/ajax_loader.gif" border=0 style="display:inline;margin-top:10px;">';
					document.getElementById("loadingbg").style.display="block";					
					SubmitFormData('create_site.php?url='+term+'', formid , term );					
				}else if( newData  == 'Yes') {
					window.location = term;
				}else if( newData == 'feedfound' ){
					window.location = document.getElementById("urf").value;
				}else if( newData == 'inserted' ||  newData == 'updated' ){
					window.location = term;
				}else if( newData == 'notexisted'){
					document.getElementById("err").innerHTML = '*The Domain does not Exist.Please enter a valid Domain Name';
				}else{
					document.getElementById(term).innerHTML = newData;
					parseScript(document.getElementById(term).innerHTML);
				}				
		   }
		});
}
function CreateProcess(uri,Formid){
	var url = CheckUrl(uri);
	if(url){
		SubmitFormData('process.php?url='+url, '', url);
	}else{
		document.getElementById("err").innerHTML = '*This is not a valid URL';
	}
	return false;
}
function dtool(url,action){
	if(url){
		document.getElementById("tools").style.display = 'block';
		document.getElementById("tools").innerHTML = 'Loading Data....';
		SubmitFormData(readCookie('SITE_PATH')+'process.php?uri='+url+'&action='+action, '', 'tools');
	}
	return false;
}
function Boxloader(action, url, did){
	document.getElementById(did).innerHTML = '<img src="'+readCookie('SITE_PATH')+'images/boxloader.gif" style="margin:40px 0px 0px 120px;" />';
	SubmitFormData(readCookie('SITE_PATH')+'process.php?uri='+url+'&action='+action, '', did);
}
function stoploading(){
	document.getElementById("loading").style.display="none";
	document.getElementById("loadingbg").style.display="none";	
} 
/**
* Cookie related functions
*/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
} 

//intiative the datepicker
function parseScript(_source) {
		var source = _source;
		var scripts = new Array();
		
		// Strip out tags
		while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
			var s = source.indexOf("<script");
			var s_e = source.indexOf(">", s);
			var e = source.indexOf("</script", s);
			var e_e = source.indexOf(">", e);
			
			// Add to scripts array
			scripts.push(source.substring(s_e+1, e));
			// Strip from source
			source = source.substring(0, s) + source.substring(e_e+1);
		}
		
		// Loop through every script collected and eval it
		for(var i=0; i<scripts.length; i++) {
			try {
				eval(scripts[i]);
			}
			catch(ex) {
				// do what you want here when a script fails
			}
		}
		// Return the cleaned source
		return source;
	}